From d525c2777406fb55e55b31b73b49f11aa65e9762 Mon Sep 17 00:00:00 2001 From: Rares Stefan Date: Tue, 21 Mar 2023 09:01:41 +0100 Subject: [PATCH] fix(admin-ui): Fix location address editing form state (#3525) I believe that changing the requiredness of the `address_1` and `country_code` fields when any part of the address was filled was not being registered correctly with the form state representation of those fields. ~~Have added an effect that unregisters the fields when the requiredness state changes and allows them to be re-registered with the correct `required` value when the next re-render happens due to that state having changed.~~ Have updated the submit button to be available even if form is invalid. Resolves CORE-1266 --- .changeset/heavy-donuts-dress.md | 5 +++++ .../inventory/locations/components/address-form/index.tsx | 8 ++++++-- .../ui/src/domain/inventory/locations/edit/index.tsx | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 .changeset/heavy-donuts-dress.md diff --git a/.changeset/heavy-donuts-dress.md b/.changeset/heavy-donuts-dress.md new file mode 100644 index 0000000000..bffe0da50d --- /dev/null +++ b/.changeset/heavy-donuts-dress.md @@ -0,0 +1,5 @@ +--- +"@medusajs/admin-ui": patch +--- + +fix(admin-ui): Fix location address editing form state diff --git a/packages/admin-ui/ui/src/domain/inventory/locations/components/address-form/index.tsx b/packages/admin-ui/ui/src/domain/inventory/locations/components/address-form/index.tsx index dd0f370daf..bfa2336456 100644 --- a/packages/admin-ui/ui/src/domain/inventory/locations/components/address-form/index.tsx +++ b/packages/admin-ui/ui/src/domain/inventory/locations/components/address-form/index.tsx @@ -78,7 +78,9 @@ const AddressForm = ({ required={addressFieldsRequired} {...register(path("address_1"), { pattern: FormValidator.whiteSpaceRule("Address 1"), - required: addressFieldsRequired, + required: addressFieldsRequired + ? "This field is required" + : undefined, })} /> { let fieldValue: diff --git a/packages/admin-ui/ui/src/domain/inventory/locations/edit/index.tsx b/packages/admin-ui/ui/src/domain/inventory/locations/edit/index.tsx index 194a67cfe2..80a8345b99 100644 --- a/packages/admin-ui/ui/src/domain/inventory/locations/edit/index.tsx +++ b/packages/admin-ui/ui/src/domain/inventory/locations/edit/index.tsx @@ -37,11 +37,11 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => { }) const notification = useNotification() - const { mutate } = useAdminUpdateStockLocation(location.id) + const { mutate, isLoading } = useAdminUpdateStockLocation(location.id) const { handleSubmit, formState } = form - const { isDirty, isValid } = formState + const { isDirty } = formState const onSubmit = handleSubmit(async (data) => { const payload = createPayload(data) @@ -85,7 +85,7 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => { size="small" variant="primary" type="button" - disabled={!isDirty || !isValid} + disabled={!isDirty || isLoading} onClick={onSubmit} > Save and close