Browse Source

fix(dashboard): Fix some form validation issues

Michael Bromley 8 months ago
parent
commit
e811e99592

+ 8 - 2
packages/dashboard/src/app/routes/_authenticated/_product-variants/product-variants_.$id.tsx

@@ -200,7 +200,9 @@ function ProductVariantDetailPage() {
                                                 <Trans>Stock level</Trans>
                                             </FormLabel>
                                             <FormControl>
-                                                <Input type="number" {...field} />
+                                                <Input type="number" value={field.value} onChange={e => {
+                                                    field.onChange(e.target.valueAsNumber);
+                                                }} />
                                             </FormControl>
                                         </FormItem>
                                     )}
@@ -224,7 +226,11 @@ function ProductVariantDetailPage() {
                                     <FormLabel>
                                         <Trans>Track inventory</Trans>
                                     </FormLabel>
-                                    <Select onValueChange={field.onChange} value={field.value}>
+                                    <Select onValueChange={val => {
+                                        if (val) {
+                                            field.onChange(val)
+                                        }
+                                    }} value={field.value}>
                                         <FormControl>
                                             <SelectTrigger className="">
                                                 <SelectValue placeholder="Track inventory" />

+ 6 - 0
packages/dashboard/src/app/routes/_authenticated/_promotions/promotions_.$id.tsx

@@ -57,6 +57,8 @@ function PromotionDetailPage() {
         transformCreateInput: values => {
             return {
                 ...values,
+                startsAt: values.startsAt || undefined,
+                endsAt: values.endsAt || undefined,
                 conditions: values.conditions.filter(c => c.code !== ''),
                 actions: values.actions.filter(a => a.code !== ''),
             };
@@ -98,6 +100,10 @@ function PromotionDetailPage() {
                 if (creatingNewEntity) {
                     await navigate({ to: `../${data.id}`, from: Route.id });
                 }
+            } else {
+                toast.error(i18n.t('Failed to update promotion'), {
+                    description: data.message,
+                });
             }
         },
         onError: err => {

+ 1 - 0
packages/dashboard/src/lib/framework/page/use-detail-page.ts

@@ -178,6 +178,7 @@ export function useDetailPage<
                 onSuccess?.((data as any)[createMutationName]);
             }
         },
+        onError,
     });
 
     const updateMutation = useMutation({