From d525c2777406fb55e55b31b73b49f11aa65e9762 Mon Sep 17 00:00:00 2001 From: Rares Stefan Date: Tue, 21 Mar 2023 09:01:41 +0100 Subject: [PATCH 1/2] 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 0000000000000..bffe0da50dc42 --- /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 dd0f370dafbdf..bfa2336456254 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 194a67cfe27c2..80a8345b995b9 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 From 497c7c55c773a62510e1ed899199dfd35c05ab3f Mon Sep 17 00:00:00 2001 From: Rares Stefan Date: Tue, 21 Mar 2023 09:12:58 +0100 Subject: [PATCH 2/2] feat(admin-ui): Encode location id in URL on location table (#3533) Encoded the `location_id` into the query params and ensured it gets parsed on mount, into defaults. This allows safer refreshes of the locations table or accurate deep-links to be shared. Resolves CORE-1252 --- .changeset/wicked-cheetahs-fail.md | 5 +++++ .../templates/inventory-table/use-inventory-filters.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/wicked-cheetahs-fail.md diff --git a/.changeset/wicked-cheetahs-fail.md b/.changeset/wicked-cheetahs-fail.md new file mode 100644 index 0000000000000..9cb2cd77cc0ed --- /dev/null +++ b/.changeset/wicked-cheetahs-fail.md @@ -0,0 +1,5 @@ +--- +"@medusajs/admin-ui": patch +--- + +feat(admin-ui): Encode location id in URL on location table diff --git a/packages/admin-ui/ui/src/components/templates/inventory-table/use-inventory-filters.ts b/packages/admin-ui/ui/src/components/templates/inventory-table/use-inventory-filters.ts index b529c5b793134..090634cbe3b18 100644 --- a/packages/admin-ui/ui/src/components/templates/inventory-table/use-inventory-filters.ts +++ b/packages/admin-ui/ui/src/components/templates/inventory-table/use-inventory-filters.ts @@ -25,7 +25,7 @@ interface InventoryFilterState { additionalFilters: InventoryDefaultFilters | null } -const allowedFilters = ["location", "q", "offset", "limit"] +const allowedFilters = ["q", "offset", "limit", "location_id"] const DefaultTabs = {} @@ -226,8 +226,8 @@ export const useInventoryFilters = ( if (value && typeof value === "string") { toQuery["q"] = value } - } else if (key === "offset" || key === "limit") { - toQuery[key] = value + } else if (key === "offset" || key === "limit" || key === "location") { + toQuery[stateFilterMap[key] || key] = value } else if (value.open) { toQuery[stateFilterMap[key]] = value.filter }