Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-commons): prompt form Form displayed on dialog validation #2089

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

skamril
Copy link
Member

@skamril skamril commented Jul 10, 2024

ANT-1858

@skamril skamril self-assigned this Jul 10, 2024
@skamril skamril requested a review from hdinia July 10, 2024 13:51
@skamril skamril added bug Something isn't working front-end labels Jul 10, 2024
@skamril skamril force-pushed the bugfix/ANT-1888_create_variant_dialog branch from 31f8bb7 to 909a55a Compare July 10, 2024 13:55
@skamril skamril changed the title fix(ui-commons): prompt displayed on dialog validation fix(ui-commons): prompt form Form displayed on dialog validation Jul 10, 2024
@@ -58,7 +58,7 @@ function CreateVariantDialog(props: Props) {

return (
<FormDialog
maxWidth="sm"
maxWidth="xs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert that change, studies names can be quite long so xs width is too small in most cases. And their is no width constraints when opening the dialog

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -116,6 +116,7 @@ function Form<TFieldValues extends FieldValues, TContext>(
const { t } = useTranslation();
const autoSubmitConfig = toAutoSubmitConfig(autoSubmit);

const [isInProgress, setIsInProgress] = useState(false);
Copy link
Member

@hdinia hdinia Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider this instead:

 const [isSubmitting, setIsSubmitting] = useState(false);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSubmitting already exist...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same component? Ok mybad didnt see that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can just add the 'submit' to indicate it refers to a submitting state like isSubmitInProgress (it's a detail tho feel free to skip)

@skamril skamril force-pushed the bugfix/ANT-1888_create_variant_dialog branch from 909a55a to 5b46996 Compare July 10, 2024 15:59
@@ -224,7 +224,7 @@ function Form<TFieldValues extends FieldValues, TContext>(
// Prevent browser close if a submit is pending
useEffect(() => {
const listener = (event: BeforeUnloadEvent) => {
if (preventClose.current) {
if (isInProgress) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSubmitting

Comment on lines +247 to +248
usePrompt(t("form.submit.inProgress"), isInProgress);
usePrompt(t("form.changeNotSaved"), isDirty && !isInProgress);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: maybe you can wrap those in a useEffect, use strict conditions, and add a cleanup for the prompt
(this can potentially lead to overlapping or competing prompts)

  useEffect(() => {
    if (isSubmitting) {
      usePrompt(t("form.submit.inProgress"), true);
    } else if (isDirty) {
      usePrompt(t("form.changeNotSaved"), true);
    } else {
      usePrompt(null, false); // Clear the prompt when no conditions are met
    }

    // Cleanup function to clear the prompt when the component unmounts
    return () => usePrompt(null, false);
  }, [isSubmitting, isDirty, t]);

@@ -116,6 +116,7 @@ function Form<TFieldValues extends FieldValues, TContext>(
const { t } = useTranslation();
const autoSubmitConfig = toAutoSubmitConfig(autoSubmit);

const [isInProgress, setIsInProgress] = useState(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same component? Ok mybad didnt see that

@@ -116,6 +116,7 @@ function Form<TFieldValues extends FieldValues, TContext>(
const { t } = useTranslation();
const autoSubmitConfig = toAutoSubmitConfig(autoSubmit);

const [isInProgress, setIsInProgress] = useState(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can just add the 'submit' to indicate it refers to a submitting state like isSubmitInProgress (it's a detail tho feel free to skip)

@skamril skamril merged commit 2b67de8 into dev Jul 11, 2024
6 of 7 checks passed
@skamril skamril deleted the bugfix/ANT-1888_create_variant_dialog branch July 11, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working front-end size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants