fix: Remove document on go back click on step 1 (#910)

 Fixes #903 
 Invoke `onBackStep` on "Go Back" click and conditionally render
Go back label string.
This commit is contained in:
Lucas Smith
2024-05-24 14:17:53 +10:00
committed by GitHub
2 changed files with 7 additions and 0 deletions

View File

@ -248,6 +248,7 @@ export const SinglePlayerClient = () => {
recipients={uploadedFile ? [placeholderRecipient] : []}
fields={fields}
onSubmit={onFieldsSubmit}
canGoBack={true}
isDocumentPdfLoaded={true}
/>
</fieldset>

View File

@ -53,6 +53,7 @@ export type AddFieldsFormProps = {
recipients: Recipient[];
fields: Field[];
onSubmit: (_data: TAddFieldsFormSchema) => void;
canGoBack?: boolean;
isDocumentPdfLoaded: boolean;
};
@ -62,10 +63,13 @@ export const AddFieldsFormPartial = ({
recipients,
fields,
onSubmit,
canGoBack = false,
isDocumentPdfLoaded,
}: AddFieldsFormProps) => {
const { isWithinPageBounds, getFieldPosition, getPage } = useDocumentElement();
const { currentStep, totalSteps, previousStep } = useStep();
const canRenderBackButtonAsRemove =
currentStep === 1 && typeof documentFlow.onBackStep === 'function' && canGoBack;
const {
control,
@ -595,7 +599,9 @@ export const AddFieldsFormPartial = ({
onGoBackClick={() => {
previousStep();
remove();
documentFlow.onBackStep?.();
}}
goBackLabel={canRenderBackButtonAsRemove ? 'Remove' : undefined}
onGoNextClick={() => void onFormSubmit()}
/>
</DocumentFlowFormContainerFooter>