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
This commit is contained in:
5
.changeset/heavy-donuts-dress.md
Normal file
5
.changeset/heavy-donuts-dress.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/admin-ui": patch
|
||||
---
|
||||
|
||||
fix(admin-ui): Fix location address editing form state
|
||||
@@ -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,
|
||||
})}
|
||||
/>
|
||||
<InputField
|
||||
@@ -113,7 +115,9 @@ const AddressForm = ({
|
||||
control={control}
|
||||
name={path("country_code")}
|
||||
rules={{
|
||||
required: addressFieldsRequired,
|
||||
required: addressFieldsRequired
|
||||
? "This field is required"
|
||||
: undefined,
|
||||
}}
|
||||
render={({ field: { value, onChange } }) => {
|
||||
let fieldValue:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user