Skip to content

Commit 1192a43

Browse files
committed
chore/ui: Add requested fixes
Signed-off-by: SeeuSim <[email protected]>
1 parent 9d0db7f commit 1192a43

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

frontend/src/components/blocks/questions/admin-delete-form.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ export const AdminDeleteForm: FC<AdminDeleteFormProps> = ({ isOpen, setIsOpen, q
3939

4040
return (
4141
<AlertDialog open={isOpen} onOpenChange={setIsOpen}>
42-
<AlertDialogContent>
42+
<AlertDialogContent className='border-border'>
4343
<AlertDialogHeader>
44-
<AlertDialogTitle className='flex'>
45-
Are you sure you want to delete question:&nbsp;`<pre>{questionId}</pre>`?
44+
<AlertDialogTitle className='text-primary flex'>
45+
Are you sure you want to delete question:&nbsp;<pre>{questionId}</pre>?
4646
</AlertDialogTitle>
4747
</AlertDialogHeader>
4848
<AlertDialogDescription />
4949
<AlertDialogFooter className='flex w-full justify-between'>
50-
<AlertDialogCancel disabled={isPending || isSuccess}>Cancel</AlertDialogCancel>
50+
<AlertDialogCancel className='text-primary' disabled={isPending || isSuccess}>
51+
Cancel
52+
</AlertDialogCancel>
5153
<AlertDialogAction
5254
onClick={(event) => {
5355
event.preventDefault();

frontend/src/components/blocks/questions/admin-edit-form.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ export const AdminEditForm: FC<AdminEditFormProps> = ({
117117
const difficultiesQuery = useQuery(getDifficultiesQueryConfig());
118118

119119
const onSubmit = (formValues: z.infer<typeof formSchema>) => {
120-
sendUpdate(formValues);
120+
const parsed = formSchema.safeParse(formValues);
121+
122+
if (parsed.success) {
123+
sendUpdate(parsed.data);
124+
}
121125
};
122126

123127
return (
@@ -200,6 +204,7 @@ export const AdminEditForm: FC<AdminEditFormProps> = ({
200204
}))}
201205
chosenOptions={field.value}
202206
setChosenOptions={(value: Array<string>) => {
207+
form.clearErrors('topics');
203208
form.setValue('topics', value);
204209
}}
205210
/>
@@ -326,7 +331,7 @@ export const AdminEditForm: FC<AdminEditFormProps> = ({
326331
<Button
327332
disabled={isPending || isSuccess}
328333
onClick={() => {
329-
onSubmit(form.getValues());
334+
form.handleSubmit(onSubmit);
330335
}}
331336
size='sm'
332337
className='flex gap-2'
@@ -335,7 +340,7 @@ export const AdminEditForm: FC<AdminEditFormProps> = ({
335340
{isPending
336341
? 'Submitting'
337342
: isSuccess
338-
? 'Updated! Closing form'
343+
? `${mode === 'create' ? 'Added' : 'Updated'}! Closing form...`
339344
: 'Save Changes'}
340345
</span>
341346
{isPending && <Loader2 className='size-4 animate-spin' />}

frontend/src/components/ui/combobox.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ export const ComboboxExternal = React.forwardRef<
118118
const [isOpen, setIsOpen] = React.useState(false);
119119
const [inputVal, setInputVal] = React.useState('');
120120

121-
const onAddNewOption = () => {
122-
const opt = inputVal.replace(/^[a-zA-Z]/, (c) => c.toUpperCase());
121+
const onAddNewOption = (newOpt?: string) => {
122+
const toAdd = newOpt ?? inputVal;
123+
const opt = toAdd.replace(/^[a-zA-Z]/, (c) => c.toUpperCase());
123124

124125
if (!chosenOptions.includes(opt)) {
125126
setChosenOptions([...chosenOptions, opt]);
@@ -149,17 +150,12 @@ export const ComboboxExternal = React.forwardRef<
149150
onValueChange={setInputVal}
150151
placeholder={`Search or add ${itemName}...`}
151152
className='h-9'
152-
onKeyDown={(event) => {
153-
if (event.key === 'Enter') {
154-
event.preventDefault();
155-
onAddNewOption();
156-
}
157-
}}
158153
/>
159154
<CommandList>
160155
<CommandEmpty
156+
autoFocus
161157
className='hover:bg-secondary hover:text-secondary-foreground p-3 text-sm hover:cursor-pointer'
162-
onClick={onAddNewOption}
158+
onClick={() => onAddNewOption()}
163159
>
164160
Add {`"${inputVal}"`}
165161
</CommandEmpty>

frontend/src/components/ui/form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const FormLabel = React.forwardRef<
8888
return (
8989
<Label
9090
ref={ref}
91-
className={cn(error && 'text-destructive', className)}
91+
className={cn(error && 'text-destructive dark:text-red-700', className)}
9292
htmlFor={formItemId}
9393
{...props}
9494
/>
@@ -146,7 +146,7 @@ const FormMessage = React.forwardRef<
146146
<p
147147
ref={ref}
148148
id={formMessageId}
149-
className={cn('text-[0.8rem] font-medium text-destructive', className)}
149+
className={cn('text-[0.8rem] font-medium text-destructive dark:text-red-700', className)}
150150
{...props}
151151
>
152152
{body}

0 commit comments

Comments
 (0)