Browse Source

fix(dashboard): Fix asset control validation

Michael Bromley 10 months ago
parent
commit
2f2a0f8565

+ 22 - 11
packages/dashboard/src/routes/_authenticated/_products/products_.$id.tsx

@@ -47,20 +47,23 @@ export function ProductDetailPage() {
         queryDocument: productDetailDocument,
         queryDocument: productDetailDocument,
         entityField: 'product',
         entityField: 'product',
         updateDocument: updateProductDocument,
         updateDocument: updateProductDocument,
-        setValuesForUpdate: entity => ({
-            id: entity.id,
-            enabled: entity.enabled,
-            featuredAssetId: entity.featuredAsset?.id,
-            assetIds: entity.assets.map(asset => asset.id),
-            facetValueIds: entity.facetValues.map(facetValue => facetValue.id),
-            translations: entity.translations.map(translation => ({
+        setValuesForUpdate: entity => {
+            // console.log(entity);
+            return {
+                id: entity.id,
+                enabled: entity.enabled,
+                featuredAssetId: entity.featuredAsset?.id,
+                assetIds: entity.assets.map(asset => asset.id),
+                facetValueIds: entity.facetValues.map(facetValue => facetValue.id),
+                translations: entity.translations.map(translation => ({
                 id: translation.id,
                 id: translation.id,
                 languageCode: translation.languageCode,
                 languageCode: translation.languageCode,
                 name: translation.name,
                 name: translation.name,
                 slug: translation.slug,
                 slug: translation.slug,
                 description: translation.description,
                 description: translation.description,
-            })),
-        }),
+                })),
+            };
+        },
         params: { id: params.id },
         params: { id: params.id },
         onSuccess: () => {
         onSuccess: () => {
             toast(i18n.t('Successfully updated product'), {
             toast(i18n.t('Successfully updated product'), {
@@ -76,6 +79,8 @@ export function ProductDetailPage() {
         },
         },
     });
     });
 
 
+    console.log(`form state:`, form.formState); 
+
     return (
     return (
         <Page>
         <Page>
             <PageTitle>{entity?.name ?? ''}</PageTitle>
             <PageTitle>{entity?.name ?? ''}</PageTitle>
@@ -202,8 +207,14 @@ export function ProductDetailPage() {
                                         compact={true}
                                         compact={true}
                                         value={form.getValues()}
                                         value={form.getValues()}
                                         onChange={value => {
                                         onChange={value => {
-                                            form.setValue('featuredAssetId', value.featuredAssetId);
-                                            form.setValue('assetIds', value.assetIds);
+                                            form.setValue('featuredAssetId', value.featuredAssetId, {
+                                                shouldDirty: true,
+                                                shouldValidate: true,
+                                            });
+                                            form.setValue('assetIds', value.assetIds, {
+                                                shouldDirty: true,
+                                                shouldValidate: true,
+                                            });
                                         }}
                                         }}
                                     />
                                     />
                                 </FormControl>
                                 </FormControl>