Skip to content

Commit

Permalink
fix(admin): addresses form issues (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayllyz authored Jul 20, 2024
1 parent 22fbe5e commit a446346
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
10 changes: 7 additions & 3 deletions apps/admin/app/ui/dashboard/addresses/AddAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function addAddress({ addresses, setAddresses }: Props): JSX.Element {
<FormItem>
<Label className="font-bold">Numéro</Label>
<FormControl>
<Input {...field} type="number" />
<Input {...field} type="number" min={1} />
</FormControl>
<FormMessage />
</FormItem>
Expand Down Expand Up @@ -214,7 +214,7 @@ function addAddress({ addresses, setAddresses }: Props): JSX.Element {
<FormItem>
<Label className="font-bold">Code postal</Label>
<FormControl>
<Input {...field} />
<Input {...field} type="number" min={0} />
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -223,7 +223,11 @@ function addAddress({ addresses, setAddresses }: Props): JSX.Element {
</div>
</div>
<div className="flex gap-4 mt-4">
<Button type="submit" className="w-full">
<Button
type="submit"
className="w-full"
disabled={form.formState.isSubmitting || !form.formState.isValid}
>
Créer
</Button>
<Button variant="secondary" type="button" onClick={() => setOpen(false)} className="w-full">
Expand Down
6 changes: 5 additions & 1 deletion apps/admin/app/ui/dashboard/addresses/AddressRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ function AddressRow(address: AddressProps) {
setOpenDelete(false);
}

if (!address || name === 'Supprimé') {
return null;
}

return (
<TableRow key={address.id}>
<TableCell className="font-medium">{name}</TableCell>
Expand Down Expand Up @@ -131,7 +135,7 @@ function AddressRow(address: AddressProps) {
<DialogDescription>
<div className="mb-4">Êtes-vous sûr de vouloir supprimer cet adresse ?</div>
<div className="flex w-full justify-end gap-4">
<Button variant="destructive" onClick={deleteAddress}>
<Button variant="destructive" onClick={deleteAddress} disabled={name === 'Supprimé'}>
Supprimer
</Button>
<Button variant="secondary" onClick={() => setOpenDelete(false)}>
Expand Down
13 changes: 9 additions & 4 deletions apps/admin/app/ui/dashboard/addresses/EditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ function EditForm(props: EditFormProps): JSX.Element {
.min(5, { message: 'Le code postal doit contenir 5 chiffres' }),
complement: z.string().optional(),
city: z.string().min(1, { message: 'Le champ est requis' }),
number: z.number({ message: 'Le numéro doit être un nombre' }).int().min(1, { message: 'Le champ est requis' }),
number: z.coerce
.number({ message: 'Le numéro doit être un nombre' })
.int()
.min(1, { message: 'Le champ est requis' }),
name: z.string().optional(),
});

Expand Down Expand Up @@ -124,7 +127,7 @@ function EditForm(props: EditFormProps): JSX.Element {
<FormItem>
<Label className="font-bold">Numéro</Label>
<FormControl>
<Input {...field} type="number" />
<Input {...field} type="number" min={1} />
</FormControl>
<FormMessage />
</FormItem>
Expand Down Expand Up @@ -184,7 +187,7 @@ function EditForm(props: EditFormProps): JSX.Element {
<FormItem>
<Label className="font-bold">Code postal</Label>
<FormControl>
<Input {...field} />
<Input {...field} type="number" min={1} />
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -193,7 +196,9 @@ function EditForm(props: EditFormProps): JSX.Element {
</div>
</div>
<div className="flex gap-4 mt-4">
<Button type="submit">Modifier</Button>
<Button type="submit" disabled={form.formState.isSubmitting || !form.formState.isValid}>
Modifier
</Button>
<Button
variant="secondary"
onClick={(e) => {
Expand Down

0 comments on commit a446346

Please sign in to comment.