-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.ts
More file actions
74 lines (58 loc) · 1.45 KB
/
Copy pathform.ts
File metadata and controls
74 lines (58 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet(
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
11
)
export type FormId = string
export type QuestionId = string
export type ChoiceId = string
export const generateFormId = (): FormId => {
return nanoid()
}
export const generateQuestionId = (): QuestionId => {
return nanoid()
}
export const generateChoiceId = (): ChoiceId => {
return nanoid()
}
export type Form = {
id: FormId
name: string
published: boolean
questions: Array<FormQuestion>
}
export type FormQuestion =
| { tag: 'shortText'; question: Question<ShortText> }
| { tag: 'longText'; question: Question<LongText> }
| { tag: 'singleChoice'; question: Question<SingleChoice> }
| { tag: 'multipleChoice'; question: Question<MultipleChoice> }
| { tag: 'scale'; question: Question<Scale> }
export type QuestionType = FormQuestion['tag']
export const allQuestionTypes: Array<QuestionType> = [
'shortText',
'longText',
'singleChoice',
'multipleChoice',
'scale',
]
export type Question<T> = {
id: QuestionId
title: string
description: string | null
required: boolean
definition: T
}
export type ShortText = null
export type LongText = null
export type Choice = {
id: ChoiceId
value: string
}
export type SingleChoice = Array<Choice>
export type MultipleChoice = Array<Choice>
export type Scale = {
start: number
end: number
startLabel: string
endLabel: string
}