Skip to content

Commit

Permalink
fix(packs): resolve type issue with questions type
Browse files Browse the repository at this point in the history
  • Loading branch information
Woofer21 committed Dec 26, 2024
1 parent 7a1f903 commit 9b180c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 1 addition & 4 deletions app/api/packs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ export async function POST(request: NextRequest) {
for (const question of preProcessedQuestions) {
questions.push({
id: uuidv4(),
type: (type === 'mixed' ? question.type : type) as Exclude<
PackType,
'mixed'
>,
type: question.type,
question: question.question
})
}
Expand Down
9 changes: 5 additions & 4 deletions app/packs/create/_components/ImportQuestionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,16 @@ function ImportDetails({
}

const finishImport = () => {
const newQuestions: { type: PackType; question: string }[] = [
...currentQuestions
]
const newQuestions: {
type: Exclude<PackType, 'mixed'>
question: string
}[] = [...currentQuestions]

for (const [key, value] of Object.entries(questions)) {
for (const question of value) {
if (question.selected) {
newQuestions.push({
type: key as PackType,
type: key as Exclude<PackType, 'mixed'>,
question: question.question
})
}
Expand Down
10 changes: 6 additions & 4 deletions utils/zod/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export const questionSchema = z.object({
.string()
.min(10, 'Make sure your question is at least 10 characters long')
.max(300, 'Make sure your question is only 300 characters long'),
type: z.nativeEnum(PackType, {
required_error: 'Please select a valid question type',
message: 'Please select a valid question type'
})
type: z
.nativeEnum(PackType, {
required_error: 'Please select a valid question type',
message: 'Please select a valid question type'
})
.refine((type) => type !== 'mixed', 'Question type cannot be mixed')
})

export const editedPackSchema = z.object({
Expand Down

0 comments on commit 9b180c1

Please sign in to comment.