Skip to content

Commit 89a748d

Browse files
committed
Fix retaining inputs
1 parent 7b242f3 commit 89a748d

1 file changed

Lines changed: 20 additions & 41 deletions

File tree

packages/react/src/components/presentation/auth/AcceptInvite/v2/BaseAcceptInvite.tsx

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
389389
delete newErrors[name];
390390
return newErrors;
391391
});
392+
setIsFormValid(true);
392393
}, []);
393394

394395
/**
@@ -414,7 +415,7 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
414415
) {
415416
const value: any = formValues[comp.ref];
416417
if (!value || value.trim() === '') {
417-
errors[comp.ref] = `${comp.label || comp.ref} is required`;
418+
errors[comp.ref] = t('validations.required.field.error');
418419
}
419420
}
420421
if (comp.components && Array.isArray(comp.components)) {
@@ -427,7 +428,7 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
427428

428429
return {errors, isValid: Object.keys(errors).length === 0};
429430
},
430-
[formValues],
431+
[formValues, t],
431432
);
432433

433434
/**
@@ -444,8 +445,8 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
444445
const validation: any = validateForm(components);
445446

446447
if (!validation.isValid) {
447-
setFormErrors(validation.errors);
448448
setIsFormValid(false);
449+
setFormErrors(validation.errors);
449450
// Mark all fields as touched
450451
const touched: Record<string, boolean> = {};
451452
Object.keys(validation.errors).forEach((key: any) => {
@@ -457,7 +458,6 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
457458

458459
setIsLoading(true);
459460
setApiError(null);
460-
setIsFormValid(true);
461461

462462
try {
463463
// Build payload with form values
@@ -512,9 +512,8 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
512512
return;
513513
}
514514

515-
// Update current flow and reset form for next step
515+
// Update current flow and reset form state for next step, preserving input values
516516
setCurrentFlow(response);
517-
setFormValues({});
518517
setFormErrors({});
519518
setTouchedFields({});
520519
} catch (err) {
@@ -626,40 +625,6 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
626625
[],
627626
);
628627

629-
/**
630-
* Render form components using the factory.
631-
*/
632-
const renderComponents: any = useCallback(
633-
(components: any[]): ReactElement[] =>
634-
renderInviteUserComponents(
635-
components,
636-
formValues,
637-
touchedFields,
638-
formErrors,
639-
isLoading,
640-
isFormValid,
641-
handleInputChange,
642-
{
643-
onInputBlur: handleInputBlur,
644-
onSubmit: handleSubmit,
645-
size,
646-
variant,
647-
},
648-
),
649-
[
650-
formValues,
651-
touchedFields,
652-
formErrors,
653-
isLoading,
654-
isFormValid,
655-
handleInputChange,
656-
handleInputBlur,
657-
handleSubmit,
658-
size,
659-
variant,
660-
],
661-
);
662-
663628
// Get components from normalized response, with fallback to meta.components
664629
const components: any = currentFlow?.data?.components || currentFlow?.data?.meta?.components || [];
665630
const {title, subtitle} = extractHeadings(components);
@@ -793,7 +758,21 @@ const BaseAcceptInvite: FC<BaseAcceptInviteProps> = ({
793758
)}
794759
<div>
795760
{componentsWithoutHeadings && componentsWithoutHeadings.length > 0
796-
? renderComponents(componentsWithoutHeadings)
761+
? renderInviteUserComponents(
762+
componentsWithoutHeadings,
763+
formValues,
764+
touchedFields,
765+
formErrors,
766+
isLoading,
767+
isFormValid,
768+
handleInputChange,
769+
{
770+
onInputBlur: handleInputBlur,
771+
onSubmit: handleSubmit,
772+
size,
773+
variant,
774+
},
775+
)
797776
: !isLoading && (
798777
<AlertPrimitive variant="warning">
799778
<Typography variant="body1">No form components available</Typography>

0 commit comments

Comments
 (0)