import type { CollectActionType } from "@hey/types/hey"; import { motion } from "motion/react"; import type { Dispatch, SetStateAction } from "react"; import { isAddress } from "viem"; import LicensePicker from "@/components/Composer/LicensePicker"; import ToggleWithHelper from "@/components/Shared/ToggleWithHelper"; import { Button } from "@/components/Shared/UI"; import { useCollectActionStore } from "@/store/non-persisted/post/useCollectActionStore"; import { usePostLicenseStore } from "@/store/non-persisted/post/usePostLicenseStore"; import { EXPANSION_EASE } from "@/variants"; import AmountConfig from "./AmountConfig"; import CollectLimitConfig from "./CollectLimitConfig"; import FollowersConfig from "./FollowersConfig"; import SplitConfig from "./SplitConfig"; import TimeLimitConfig from "./TimeLimitConfig"; interface CollectFormProps { setShowModal: Dispatch>; } const CollectForm = ({ setShowModal }: CollectFormProps) => { const { collectAction, setCollectAction, reset } = useCollectActionStore(); const { setLicense } = usePostLicenseStore(); const recipients = collectAction.payToCollect?.recipients || []; const splitTotal = recipients.reduce((acc, { percent }) => acc + percent, 0); const validationChecks = { hasEmptyRecipients: recipients.some(({ address }) => !address), hasImproperSplits: recipients.length > 1 && splitTotal !== 100, hasInvalidEthAddress: recipients.some( ({ address }) => address && !isAddress(address) ), hasZeroSplits: recipients.some(({ percent }) => percent === 0), isRecipientsDuplicated: new Set(recipients.map(({ address }) => address)).size !== recipients.length }; const setCollectType = (data: CollectActionType) => { setCollectAction({ ...collectAction, ...data }); }; const toggleCollect = () => { if (collectAction.enabled) { setLicense(null); reset(); } else { setCollectType({ enabled: true }); } }; const handleClose = () => { setShowModal(false); setLicense(null); reset(); }; return ( <>
{collectAction.enabled && ( <> {collectAction.payToCollect?.erc20?.value && ( )}
)}
); }; export default CollectForm;