From dd598ee0d14d615d67c6117dfe1fdc9edc4410f3 Mon Sep 17 00:00:00 2001 From: "Carina.Akaia.io" Date: Fri, 14 Jun 2024 08:53:35 +0400 Subject: [PATCH] wip --- src/common/ui/components/dialog.tsx | 26 +++++++------ .../donation/components/DonationModal.tsx | 25 ++---------- .../donation/components/DonationToPot.tsx | 10 +++-- .../donation/components/DonationToProject.tsx | 39 ++++++++++--------- src/modules/donation/index.ts | 25 +++++++++++- src/modules/donation/models.ts | 3 ++ 6 files changed, 73 insertions(+), 55 deletions(-) diff --git a/src/common/ui/components/dialog.tsx b/src/common/ui/components/dialog.tsx index 1954252c..d51ac8d5 100644 --- a/src/common/ui/components/dialog.tsx +++ b/src/common/ui/components/dialog.tsx @@ -61,18 +61,20 @@ const DialogContent = forwardRef< > {children} - - - Close - +
+ + + Close + +
)); diff --git a/src/modules/donation/components/DonationModal.tsx b/src/modules/donation/components/DonationModal.tsx index 597d1586..f9c02000 100644 --- a/src/modules/donation/components/DonationModal.tsx +++ b/src/modules/donation/components/DonationModal.tsx @@ -2,13 +2,13 @@ import { useCallback } from "react"; import { create, useModal } from "@ebay/nice-modal-react"; -import { AccountId, PotId } from "@/common/api/potlock"; import { Dialog, DialogContent } from "@/common/ui/components"; import { DonationToPot } from "./DonationToPot"; import { DonationToProject } from "./DonationToProject"; +import { DonationInputs, DonationState } from "../models"; -export type DonationModalProps = { accountId: AccountId } | { potId: PotId }; +export type DonationModalProps = DonationInputs & DonationState; export const DonationModal = create((props: DonationModalProps) => { const self = useModal(); @@ -22,28 +22,11 @@ export const DonationModal = create((props: DonationModalProps) => { {"accountId" in props && ( - + )} - {"potId" in props && ( - - )} + {"potId" in props && } ); }); - -export const useDonationModal = (props: DonationModalProps) => { - const modal = useModal(DonationModal); - - return { - openDonationModal: useCallback( - (event: React.MouseEvent) => { - event.preventDefault(); - modal.show(props); - }, - - [modal, props], - ), - }; -}; diff --git a/src/modules/donation/components/DonationToPot.tsx b/src/modules/donation/components/DonationToPot.tsx index 2d791ff4..662d5876 100644 --- a/src/modules/donation/components/DonationToPot.tsx +++ b/src/modules/donation/components/DonationToPot.tsx @@ -5,13 +5,17 @@ import { DialogTitle, } from "@/common/ui/components"; -export type DonationToPotProps = ByPotId & { - closeDialog: VoidFunction; -}; +import { DonationState } from "../models"; + +export type DonationToPotProps = ByPotId & + DonationState & { + closeDialog: VoidFunction; + }; export const DonationToPot: React.FC = ({ potId, closeDialog: _, + currentStep: __, }) => { const { isLoading, data: pot, error } = potlock.usePot({ potId }); diff --git a/src/modules/donation/components/DonationToProject.tsx b/src/modules/donation/components/DonationToProject.tsx index 37b39a64..cbb6b70b 100644 --- a/src/modules/donation/components/DonationToProject.tsx +++ b/src/modules/donation/components/DonationToProject.tsx @@ -1,6 +1,6 @@ import { useMemo } from "react"; -import { dispatch, useTypedSelector } from "@/app/_store"; +import { dispatch } from "@/app/_store"; import { ByAccountId, potlock } from "@/common/api/potlock"; import { Button, @@ -21,17 +21,18 @@ import { } from "@/common/ui/components"; import { useProjectDonationForm } from "../hooks/project-donation"; +import { DonationState } from "../models"; -export type DonationToProjectProps = ByAccountId & { - closeDialog: VoidFunction; -}; +export type DonationToProjectProps = ByAccountId & + DonationState & { + closeDialog: VoidFunction; + }; export const DonationToProject: React.FC = ({ accountId, closeDialog: _, + currentStep, }) => { - const { currentStep } = useTypedSelector(({ donation }) => donation); - const { isLoading: isAccountLoading, data: account, @@ -43,11 +44,11 @@ export const DonationToProject: React.FC = ({ const { onSubmit, ...form } = useProjectDonationForm({}); - const currentScreen = useMemo(() => { + const content = useMemo(() => { switch (currentStep) { case "allocation": return ( - <> +
How do you want to allocate funds? @@ -108,7 +109,7 @@ export const DonationToProject: React.FC = ({ step={0.01} appendix="$ 0.00" /> - +
); case "confirmation": return <>; @@ -136,15 +137,17 @@ export const DonationToProject: React.FC = ({ {account !== undefined && ( <> - - - {`Donation to ${account.near_social_profile_data?.name}`} - - - - -
{currentScreen}
-
+ {currentStep !== "done" && ( + + + {currentStep === "confirmation" + ? "Confirm donation" + : `Donation to ${account.near_social_profile_data?.name}`} + + + )} + + {content}