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:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/admin-ui": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(admin-ui): Fix location address editing form state
|
||||||
+6
-2
@@ -78,7 +78,9 @@ const AddressForm = ({
|
|||||||
required={addressFieldsRequired}
|
required={addressFieldsRequired}
|
||||||
{...register(path("address_1"), {
|
{...register(path("address_1"), {
|
||||||
pattern: FormValidator.whiteSpaceRule("Address 1"),
|
pattern: FormValidator.whiteSpaceRule("Address 1"),
|
||||||
required: addressFieldsRequired,
|
required: addressFieldsRequired
|
||||||
|
? "This field is required"
|
||||||
|
: undefined,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<InputField
|
<InputField
|
||||||
@@ -113,7 +115,9 @@ const AddressForm = ({
|
|||||||
control={control}
|
control={control}
|
||||||
name={path("country_code")}
|
name={path("country_code")}
|
||||||
rules={{
|
rules={{
|
||||||
required: addressFieldsRequired,
|
required: addressFieldsRequired
|
||||||
|
? "This field is required"
|
||||||
|
: undefined,
|
||||||
}}
|
}}
|
||||||
render={({ field: { value, onChange } }) => {
|
render={({ field: { value, onChange } }) => {
|
||||||
let fieldValue:
|
let fieldValue:
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => {
|
|||||||
})
|
})
|
||||||
const notification = useNotification()
|
const notification = useNotification()
|
||||||
|
|
||||||
const { mutate } = useAdminUpdateStockLocation(location.id)
|
const { mutate, isLoading } = useAdminUpdateStockLocation(location.id)
|
||||||
|
|
||||||
const { handleSubmit, formState } = form
|
const { handleSubmit, formState } = form
|
||||||
|
|
||||||
const { isDirty, isValid } = formState
|
const { isDirty } = formState
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (data) => {
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
const payload = createPayload(data)
|
const payload = createPayload(data)
|
||||||
@@ -85,7 +85,7 @@ const LocationEditModal = ({ onClose, location }: LocationEditModalProps) => {
|
|||||||
size="small"
|
size="small"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
type="button"
|
type="button"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || isLoading}
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
>
|
>
|
||||||
Save and close
|
Save and close
|
||||||
|
|||||||
Reference in New Issue
Block a user