-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapplication-settings.tsx
More file actions
203 lines (185 loc) · 6.64 KB
/
application-settings.tsx
File metadata and controls
203 lines (185 loc) · 6.64 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { Dispatch, SetStateAction } from "react";
import * as React from "react";
import { useCallback } from "react";
import type { ApplicationSettingsDTO } from "../../../api/types/dto";
import { useSettingsContext } from "../../../contexts/settings-context";
import { useDerivedState } from "../../../hooks/use-derived-state";
import { isValidDate } from "../../../util";
import { Collapsible } from "../../base/collapsible";
import { Spacer } from "../../base/flex";
import { FlexRowColumnContainer, FlexRowContainer } from "../../base/flex";
import { Text } from "../../base/text";
import { TextInput, TextInputType } from "../../base/text-input";
import { FormEditor } from "./form-editor";
import { SettingsSection } from "../settings-section";
/**
* Settings to configure the application users have to fill out.
*/
export const ApplicationSettings = () => {
const { settings, updateSettings } = useSettingsContext();
const updateApplicationSettings = useCallback(
(changes: Partial<ApplicationSettingsDTO>) => {
updateSettings({
...settings,
application: {
...settings.application,
...changes,
},
});
},
[updateSettings, settings],
);
const handleHoursToConfirmChange = useCallback(
(hoursToConfirm: number) => updateApplicationSettings({ hoursToConfirm }),
[updateApplicationSettings],
);
const [allowProfileFormFrom, setAllowProfileFormFrom] = useDerivedState(
() => settings.application.allowProfileFormFrom.toISOString(),
[settings],
);
const [allowProfileFormUntil, setAllowProfileFormUntil] = useDerivedState(
() => settings.application.allowProfileFormUntil.toISOString(),
[settings],
);
const [acceptanceDeadline, setAcceptanceDeadline] = useDerivedState(
() => settings.application.acceptanceDeadline.toISOString(),
[settings],
);
const [confirmSpotUntil, setConfirmSpotUntil] = useDerivedState(
() => settings.application.confirmSpotUntil.toISOString(),
[settings],
);
const handleDateChange = useCallback(
(value: string, setter: Dispatch<SetStateAction<string>>, key: string) => {
setter(value);
const date = new Date(value);
if (!isValidDate(date)) {
return;
}
updateApplicationSettings({
[key]: date,
});
},
[updateApplicationSettings],
);
const handleProfileFormChange = useCallback(
(profileForm: ApplicationSettingsDTO["profileForm"]) =>
updateApplicationSettings({ profileForm }),
[updateApplicationSettings],
);
const handleConfirmationFormChange = useCallback(
(confirmationForm: ApplicationSettingsDTO["confirmationForm"]) =>
updateApplicationSettings({ confirmationForm }),
[updateApplicationSettings],
);
return (
<SettingsSection title="Application">
<Text>
An application is divided into two parts: the profile form and the
confirmation phase. Once you accept applications, the users will be
moved to the confirmation queue, where they'll need to fill out the
remaining questions. If you add questions to the first phase after users
submitted the first answers, tilt will ask these new questions in the
confirmation phase. Depending on whether you need their consent, ensure
these added questions are mandatory.
</Text>
<FlexRowContainer>
<FlexRowColumnContainer>
<TextInput
value={settings.application.hoursToConfirm}
onChange={handleHoursToConfirmChange}
type={TextInputType.Number}
min={1}
title="Hours to confirm"
placeholder="keep it fair, e.g. 240 for 10 days"
/>
</FlexRowColumnContainer>
</FlexRowContainer>
<FlexRowContainer>
<FlexRowColumnContainer>
<TextInput
value={allowProfileFormFrom}
onChange={(value) =>
handleDateChange(
value,
setAllowProfileFormFrom,
"allowProfileFormFrom",
)
}
title="Open registration on"
placeholder="1970-01-01 00:00:00"
/>
</FlexRowColumnContainer>
<Spacer />
<FlexRowColumnContainer>
<TextInput
value={allowProfileFormUntil}
onChange={(value) =>
handleDateChange(
value,
setAllowProfileFormUntil,
"allowProfileFormUntil",
)
}
title="Close registration on"
placeholder="1970-01-01 00:00:00"
/>
</FlexRowColumnContainer>
</FlexRowContainer>
<FlexRowContainer>
<FlexRowColumnContainer>
<TextInput
value={acceptanceDeadline}
onChange={(value) =>
handleDateChange(
value,
setAcceptanceDeadline,
"acceptanceDeadline",
)
}
title="When we will accept people"
placeholder="1970-01-01 00:00:00"
/>
</FlexRowColumnContainer>
<Spacer />
<FlexRowColumnContainer>
<TextInput
value={confirmSpotUntil}
onChange={(value) =>
handleDateChange(value, setConfirmSpotUntil, "confirmSpotUntil")
}
title="Until when accepted people need to confirm their spot"
placeholder="1970-01-01 00:00:00"
/>
</FlexRowColumnContainer>
</FlexRowContainer>
<Text>
Use the add button to add new questions and the edit button in the top
right of each question to modify them. You may use Markdown syntax in
the description, but please keep it short.
</Text>
<Text>
Questions can have parents, which you can use to conditionally show
other questions. For instance, if you have a question, whether someone
is a student, you could use it to modify subsequent questions by
referencing the user's answer to that question. Tilt checks for cycles,
but consider your users filling out the form, i.e. don't conditionally
show questions on the top when selecting something at the bottom of the
form.
</Text>
<Spacer />
<Collapsible title="Profile form">
<FormEditor
form={settings.application.profileForm}
onFormChange={handleProfileFormChange}
/>
</Collapsible>
<Collapsible title="Confirmation form">
<FormEditor
form={settings.application.confirmationForm}
onFormChange={handleConfirmationFormChange}
/>
</Collapsible>
</SettingsSection>
);
};