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] : []} recipients={uploadedFile ? [placeholderRecipient] : []}
fields={fields} fields={fields}
onSubmit={onFieldsSubmit} onSubmit={onFieldsSubmit}
canGoBack={true}
isDocumentPdfLoaded={true} isDocumentPdfLoaded={true}
/> />
</fieldset> </fieldset>

View File

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