Skip to content

Commit

Permalink
Merge pull request #524 from trilitech/hide-preview-button-for-batch
Browse files Browse the repository at this point in the history
Hide preview button for batch
  • Loading branch information
ryutamago authored Oct 25, 2023
2 parents a99dd3e + 73df666 commit e99e2c4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/components/SendFlow/Tez/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const toOperation = (formValues: FormValues): TezTransfer => ({
recipient: parsePkh(formValues.recipient),
});

const FormPage: React.FC<FormPageProps<FormValues>> = props => {
const FormPage: React.FC<FormPageProps<FormValues> & { showPreview?: boolean }> = ({
showPreview = true,
...props
}) => {
const openSignPage = useOpenSignPageFormAction({
SignPage,
signPageExtraData: undefined,
Expand Down Expand Up @@ -126,6 +129,7 @@ const FormPage: React.FC<FormPageProps<FormValues>> = props => {
isValid={isValid}
onSingleSubmit={handleSubmit(onSingleSubmit)}
onAddToBatch={handleSubmit(onBatchSubmit)}
showPreview={showPreview}
/>
</ModalFooter>
</form>
Expand Down
27 changes: 27 additions & 0 deletions src/components/SendFlow/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ describe("SendFlow utils", () => {
fireEvent.click(screen.getByText("Insert Into Batch"));
expect(mockSingle).toHaveBeenCalled();
});

it("shows preview button by default", () => {
render(
<FormSubmitButtons
isLoading={false}
isValid={true}
onSingleSubmit={async () => {}}
onAddToBatch={async () => {}}
/>
);

expect(screen.getByText("Preview")).toBeInTheDocument();
});

it("hides preview button", () => {
render(
<FormSubmitButtons
showPreview={false}
isLoading={false}
isValid={true}
onSingleSubmit={async () => {}}
onAddToBatch={async () => {}}
/>
);

expect(screen.queryByText("Preview")).not.toBeInTheDocument();
});
});

describe("smallestUnit", () => {
Expand Down
26 changes: 15 additions & 11 deletions src/components/SendFlow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,30 @@ export const FormSubmitButtons = ({
isValid,
onSingleSubmit,
onAddToBatch,
showPreview = true,
}: {
isLoading: boolean;
isValid: boolean;
onSingleSubmit: () => Promise<void>;
onAddToBatch: () => Promise<void>;
showPreview?: boolean;
}) => {
return (
<>
<Box width="100%">
<Button
onClick={onSingleSubmit}
width="100%"
size="lg"
isLoading={isLoading}
type="submit"
isDisabled={!isValid}
mb="16px"
>
Preview
</Button>
{showPreview && (
<Button
onClick={onSingleSubmit}
width="100%"
size="lg"
isLoading={isLoading}
type="submit"
isDisabled={!isValid}
mb="16px"
>
Preview
</Button>
)}
<Button
onClick={onAddToBatch}
width="100%"
Expand Down
4 changes: 3 additions & 1 deletion src/views/batch/BatchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const EmptyBatch = () => {
</Text>
<Flex justifyContent="space-around" mt="30px">
<Box>
<Button onClick={() => openWith(<SendTezForm />)}>Start a Batch</Button>
<Button onClick={() => openWith(<SendTezForm showPreview={false} />)}>
Start a Batch
</Button>
<Button ml="15px" variant="tertiary" onClick={() => openWith(<CSVFileUploadForm />)}>
Load CSV file
</Button>
Expand Down

0 comments on commit e99e2c4

Please sign in to comment.