Adding location: Error message bypass submit button being disabled (#1367)

Form location error message submit fix
This commit is contained in:
ameer2468 2023-09-22 01:22:21 +03:00 committed by GitHub
parent 3cd55bb551
commit 7f5d6e8fdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -197,6 +197,7 @@ export const AddLocationDialog = ({
dialog={useDialog(dialogProps)}
onSubmit={onSubmit}
ctaLabel="Add"
errorMessageException="Location is already linked"
description={
platform.platform === 'web'
? 'As you are using the browser version of Spacedrive you will (for now) ' +

View file

@ -126,6 +126,7 @@ export interface DialogProps<S extends FieldValues>
transformOrigin?: string;
buttonsSideContent?: ReactNode;
invertButtonFocus?: boolean; //this reverses the focus order of submit/cancel buttons
errorMessageException?: string; //this is to bypass a specific form error message if it starts with a specific string
}
export function Dialog<S extends FieldValues>({
@ -181,7 +182,13 @@ export function Dialog<S extends FieldValues>({
type="submit"
size="sm"
disabled={
form.formState.isSubmitting || props.submitDisabled || !form.formState.isValid
form.formState.isSubmitting ||
props.submitDisabled ||
(!form.formState.isValid || props.errorMessageException
? !form.formState.errors.root?.serverError?.message?.startsWith(
props.errorMessageException as string
)
: false)
}
variant={props.ctaDanger ? 'colored' : 'accent'}
className={clsx(