🐛 event/exam form layout refinement + remove redundant duration
Browse files at this commit8f18549b60fa4bf7e27f7c9f8ba34c53087ec2deParent: 6505c30- fix
- 🐛 event/exam form layout refinement + remove redundant duration
3 changed files +24 -36
- src/components/events/event-card.tsx +1 -1
- src/components/events/event-form.tsx +15 -5
- src/components/exams/exam-form.tsx +8 -30
src/components/events/event-card.tsxmodified+1 -1
| @@ -18,7 +18,7 @@ export function EventCard(props: { event: Event }) { | |||
| 18 | </p> | 18 | </p> |
| 19 | </div> | 19 | </div> |
| 20 | <div class="border-t border-border bg-muted/25 px-3 py-3"> | 20 | <div class="border-t border-border bg-muted/25 px-3 py-3"> |
| 21 | - <dl class="grid gap-2 text-xs text-muted-foreground sm:grid-cols-2"> | 21 | + <dl class="grid gap-2 text-xs text-muted-foreground"> |
| 22 | <div> | 22 | <div> |
| 23 | <dt class="font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.starts")}</dt> | 23 | <dt class="font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.starts")}</dt> |
| 24 | <dd class="mono mt-1 text-foreground">{formatDateTime(props.event.starts_at, locale())}</dd> | 24 | <dd class="mono mt-1 text-foreground">{formatDateTime(props.event.starts_at, locale())}</dd> |
src/components/events/event-form.tsxmodified+15 -5
| @@ -159,12 +159,13 @@ export function EventForm(props: { | |||
| 159 | onInput={(e) => setDescription(e.currentTarget.value)} | 159 | onInput={(e) => setDescription(e.currentTarget.value)} |
| 160 | /> | 160 | /> |
| 161 | </div> | 161 | </div> |
| 162 | - <div class="grid gap-3 sm:grid-cols-2"> | 162 | + <div class="grid gap-3"> |
| 163 | <div class="space-y-1.5"> | 163 | <div class="space-y-1.5"> |
| 164 | <Label for="event-starts">{t("events.starts")}</Label> | 164 | <Label for="event-starts">{t("events.starts")}</Label> |
| 165 | - <div class="grid grid-cols-[minmax(0,1fr)_6.5rem] gap-2"> | 165 | + <div class="grid grid-cols-2 gap-2"> |
| 166 | <DatePicker | 166 | <DatePicker |
| 167 | id="event-starts" | 167 | id="event-starts" |
| 168 | + class="h-10" | ||
| 168 | placeholder={t("form.datePlaceholder")} | 169 | placeholder={t("form.datePlaceholder")} |
| 169 | value={startsDate()} | 170 | value={startsDate()} |
| 170 | onChange={(value) => { | 171 | onChange={(value) => { |
| @@ -173,9 +174,13 @@ export function EventForm(props: { | |||
| 173 | }} | 174 | }} |
| 174 | /> | 175 | /> |
| 175 | <Input | 176 | <Input |
| 176 | - class="h-10 rounded-sm font-mono" | 177 | + id="event-starts-time" |
| 178 | + class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/45" | ||
| 179 | + inputMode="numeric" | ||
| 177 | placeholder="09:00" | 180 | placeholder="09:00" |
| 181 | + pattern="[0-2][0-9]:[0-5][0-9]" | ||
| 178 | value={startsTime()} | 182 | value={startsTime()} |
| 183 | + aria-label={t("exams.startTime")} | ||
| 179 | onInput={(e) => { | 184 | onInput={(e) => { |
| 180 | setStartsTime(e.currentTarget.value); | 185 | setStartsTime(e.currentTarget.value); |
| 181 | setStartsTouched(true); | 186 | setStartsTouched(true); |
| @@ -188,9 +193,10 @@ export function EventForm(props: { | |||
| 188 | </div> | 193 | </div> |
| 189 | <div class="space-y-1.5"> | 194 | <div class="space-y-1.5"> |
| 190 | <Label for="event-ends">{t("events.ends")}</Label> | 195 | <Label for="event-ends">{t("events.ends")}</Label> |
| 191 | - <div class="grid grid-cols-[minmax(0,1fr)_6.5rem] gap-2"> | 196 | + <div class="grid grid-cols-2 gap-2"> |
| 192 | <DatePicker | 197 | <DatePicker |
| 193 | id="event-ends" | 198 | id="event-ends" |
| 199 | + class="h-10" | ||
| 194 | placeholder={t("form.datePlaceholder")} | 200 | placeholder={t("form.datePlaceholder")} |
| 195 | value={endsDate()} | 201 | value={endsDate()} |
| 196 | onChange={(value) => { | 202 | onChange={(value) => { |
| @@ -199,9 +205,13 @@ export function EventForm(props: { | |||
| 199 | }} | 205 | }} |
| 200 | /> | 206 | /> |
| 201 | <Input | 207 | <Input |
| 202 | - class="h-10 rounded-sm font-mono" | 208 | + id="event-ends-time" |
| 209 | + class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/45" | ||
| 210 | + inputMode="numeric" | ||
| 203 | placeholder="10:00" | 211 | placeholder="10:00" |
| 212 | + pattern="[0-2][0-9]:[0-5][0-9]" | ||
| 204 | value={endsTime()} | 213 | value={endsTime()} |
| 214 | + aria-label={t("exams.endTime")} | ||
| 205 | onInput={(e) => { | 215 | onInput={(e) => { |
| 206 | setEndsTime(e.currentTarget.value); | 216 | setEndsTime(e.currentTarget.value); |
| 207 | setEndsTouched(true); | 217 | setEndsTouched(true); |
src/components/exams/exam-form.tsxmodified+8 -30
| @@ -28,11 +28,6 @@ function timeInputFromMs(ms: number | null | undefined): string { | |||
| 28 | return `${pad(d.getHours())}:${pad(d.getMinutes())}`; | 28 | return `${pad(d.getHours())}:${pad(d.getMinutes())}`; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | -function durationMinutesFromMs(ms: number | null | undefined): string { | ||
| 32 | - if (ms == null) return ""; | ||
| 33 | - return String(Math.round(ms / 60000)); | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | function scheduleInputToMs(date: string, time: string): number | null { | 31 | function scheduleInputToMs(date: string, time: string): number | null { |
| 37 | const dateMatch = date.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); | 32 | const dateMatch = date.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); |
| 38 | const timeMatch = time.trim().match(/^(\d{2}):(\d{2})$/); | 33 | const timeMatch = time.trim().match(/^(\d{2}):(\d{2})$/); |
| @@ -87,7 +82,6 @@ export function ExamForm(props: { | |||
| 87 | const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at)); | 82 | const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at)); |
| 88 | const [endsDate, setEndsDate] = createSignal(dateInputFromMs(props.initial?.ends_at)); | 83 | const [endsDate, setEndsDate] = createSignal(dateInputFromMs(props.initial?.ends_at)); |
| 89 | const [endsTime, setEndsTime] = createSignal(timeInputFromMs(props.initial?.ends_at)); | 84 | const [endsTime, setEndsTime] = createSignal(timeInputFromMs(props.initial?.ends_at)); |
| 90 | - const [durationMinutes, setDurationMinutes] = createSignal(durationMinutesFromMs(props.initial?.duration_ms)); | ||
| 91 | const [error, setError] = createSignal(""); | 85 | const [error, setError] = createSignal(""); |
| 92 | const [pending, setPending] = createSignal(false); | 86 | const [pending, setPending] = createSignal(false); |
| 93 | const [confirmOpen, setConfirmOpen] = createSignal(false); | 87 | const [confirmOpen, setConfirmOpen] = createSignal(false); |
| @@ -140,7 +134,6 @@ export function ExamForm(props: { | |||
| 140 | setStartsTime(""); | 134 | setStartsTime(""); |
| 141 | setEndsDate(""); | 135 | setEndsDate(""); |
| 142 | setEndsTime(""); | 136 | setEndsTime(""); |
| 143 | - setDurationMinutes(""); | ||
| 144 | } | 137 | } |
| 145 | } catch (err) { | 138 | } catch (err) { |
| 146 | setError(formatApiError(err)); | 139 | setError(formatApiError(err)); |
| @@ -154,8 +147,7 @@ export function ExamForm(props: { | |||
| 154 | const hasWindow = mode() === "sync" || mode() === "async"; | 147 | const hasWindow = mode() === "sync" || mode() === "async"; |
| 155 | const starts_at = hasWindow ? scheduleInputToMs(startsDate(), startsTime()) : null; | 148 | const starts_at = hasWindow ? scheduleInputToMs(startsDate(), startsTime()) : null; |
| 156 | const ends_at = hasWindow ? scheduleInputToMs(endsDate(), endsTime()) : null; | 149 | const ends_at = hasWindow ? scheduleInputToMs(endsDate(), endsTime()) : null; |
| 157 | - const durationValue = Number(durationMinutes()); | 150 | + const duration_ms = mode() === "async" && starts_at != null && ends_at != null ? ends_at - starts_at : null; |
| 158 | - const duration_ms = mode() === "async" && Number.isFinite(durationValue) ? durationValue * 60000 : null; | ||
| 159 | const v = validate(starts_at, ends_at, duration_ms); | 151 | const v = validate(starts_at, ends_at, duration_ms); |
| 160 | if (v) { | 152 | if (v) { |
| 161 | setError(v); | 153 | setError(v); |
| @@ -251,7 +243,7 @@ export function ExamForm(props: { | |||
| 251 | <Label for="exam-max-attempts">{t("exams.maxAttempts")}</Label> | 243 | <Label for="exam-max-attempts">{t("exams.maxAttempts")}</Label> |
| 252 | <Input | 244 | <Input |
| 253 | id="exam-max-attempts" | 245 | id="exam-max-attempts" |
| 254 | - class="rounded-sm" | 246 | + class="h-10 rounded-sm bg-background/60" |
| 255 | type="number" | 247 | type="number" |
| 256 | min={1} | 248 | min={1} |
| 257 | step={1} | 249 | step={1} |
| @@ -266,9 +258,10 @@ export function ExamForm(props: { | |||
| 266 | <div class="grid gap-3"> | 258 | <div class="grid gap-3"> |
| 267 | <div class="space-y-1.5"> | 259 | <div class="space-y-1.5"> |
| 268 | <Label for="exam-starts">{t("events.starts")}</Label> | 260 | <Label for="exam-starts">{t("events.starts")}</Label> |
| 269 | - <div class="grid grid-cols-[minmax(0,1fr)_7rem] gap-2"> | 261 | + <div class="grid grid-cols-2 gap-2"> |
| 270 | <DatePicker | 262 | <DatePicker |
| 271 | id="exam-starts" | 263 | id="exam-starts" |
| 264 | + class="h-10" | ||
| 272 | placeholder={t("form.datePlaceholder")} | 265 | placeholder={t("form.datePlaceholder")} |
| 273 | value={startsDate()} | 266 | value={startsDate()} |
| 274 | required | 267 | required |
| @@ -276,7 +269,7 @@ export function ExamForm(props: { | |||
| 276 | /> | 269 | /> |
| 277 | <Input | 270 | <Input |
| 278 | id="exam-starts-time" | 271 | id="exam-starts-time" |
| 279 | - class="rounded-sm font-mono placeholder:text-muted-foreground/45" | 272 | + class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/45" |
| 280 | inputMode="numeric" | 273 | inputMode="numeric" |
| 281 | placeholder="14:30" | 274 | placeholder="14:30" |
| 282 | pattern="[0-2][0-9]:[0-5][0-9]" | 275 | pattern="[0-2][0-9]:[0-5][0-9]" |
| @@ -289,9 +282,10 @@ export function ExamForm(props: { | |||
| 289 | </div> | 282 | </div> |
| 290 | <div class="space-y-1.5"> | 283 | <div class="space-y-1.5"> |
| 291 | <Label for="exam-ends">{t("events.ends")}</Label> | 284 | <Label for="exam-ends">{t("events.ends")}</Label> |
| 292 | - <div class="grid grid-cols-[minmax(0,1fr)_7rem] gap-2"> | 285 | + <div class="grid grid-cols-2 gap-2"> |
| 293 | <DatePicker | 286 | <DatePicker |
| 294 | id="exam-ends" | 287 | id="exam-ends" |
| 288 | + class="h-10" | ||
| 295 | placeholder={t("form.datePlaceholder")} | 289 | placeholder={t("form.datePlaceholder")} |
| 296 | value={endsDate()} | 290 | value={endsDate()} |
| 297 | required | 291 | required |
| @@ -299,7 +293,7 @@ export function ExamForm(props: { | |||
| 299 | /> | 293 | /> |
| 300 | <Input | 294 | <Input |
| 301 | id="exam-ends-time" | 295 | id="exam-ends-time" |
| 302 | - class="rounded-sm font-mono placeholder:text-muted-foreground/45" | 296 | + class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/45" |
| 303 | inputMode="numeric" | 297 | inputMode="numeric" |
| 304 | placeholder="15:30" | 298 | placeholder="15:30" |
| 305 | pattern="[0-2][0-9]:[0-5][0-9]" | 299 | pattern="[0-2][0-9]:[0-5][0-9]" |
| @@ -312,22 +306,6 @@ export function ExamForm(props: { | |||
| 312 | </div> | 306 | </div> |
| 313 | </div> | 307 | </div> |
| 314 | </Show> | 308 | </Show> |
| 315 | - <Show when={mode() === "async"}> | ||
| 316 | - <div class="space-y-1.5"> | ||
| 317 | - <Label for="exam-duration-minutes">{t("exams.durationMinutes")}</Label> | ||
| 318 | - <Input | ||
| 319 | - id="exam-duration-minutes" | ||
| 320 | - class="rounded-sm" | ||
| 321 | - type="number" | ||
| 322 | - min={1} | ||
| 323 | - max={1440} | ||
| 324 | - step={1} | ||
| 325 | - value={durationMinutes()} | ||
| 326 | - required | ||
| 327 | - onInput={(e) => setDurationMinutes(e.currentTarget.value)} | ||
| 328 | - /> | ||
| 329 | - </div> | ||
| 330 | - </Show> | ||
| 331 | {error() && <p class="text-sm text-destructive">{error()}</p>} | 309 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 332 | <div class="flex flex-wrap items-center gap-2"> | 310 | <div class="flex flex-wrap items-center gap-2"> |
| 333 | <Button type="submit" disabled={pending()}> | 311 | <Button type="submit" disabled={pending()}> |