diff --git a/src/features/admin/manage-zap-split.tsx b/src/features/admin/manage-zap-split.tsx new file mode 100644 index 000000000..31f2b4197 --- /dev/null +++ b/src/features/admin/manage-zap-split.tsx @@ -0,0 +1,115 @@ +import React, { useState } from 'react'; +import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; + +import Account from 'soapbox/components/account'; +import List, { ListItem } from 'soapbox/components/list'; +import { Button, Column, HStack, Stack } from 'soapbox/components/ui'; + +import { useManageZapSplit } from '../../api/hooks/admin/useManageZapSplit'; +import AddNewAccount from '../ui/components/new-account-zap-split'; +import { ZapSplitSlider } from '../zap/components/zap-split-account-item'; + +const closeIcon = require('@tabler/icons/outline/x.svg'); + +const messages = defineMessages({ + heading: { id: 'column.admin.zap_split', defaultMessage: 'Manage Zap Split' }, +}); + +interface INewAccount{ + acc: string; + message: string; + weight: number; +} + +const ManageZapSplit: React.FC = () => { + const intl = useIntl(); + const { formattedData, weights, handleWeightChange, sendNewSplit, removeAccount } = useManageZapSplit(); + const [hasNewAccount, setHasNewAccount] = useState(false); + const [newWeight, setNewWeight] = useState(0.05); + const [newAccount, setNewAccount] = useState({ acc: '', message: '', weight: Number((newWeight * 100).toFixed()) }); + + const handleNewAccount = () => { + setHasNewAccount(false); + console.log(newAccount); + + sendNewSplit(newAccount); + + setNewWeight(0.05); + setNewAccount(({ acc: '', message: '', weight: Number((newWeight * 100).toFixed()) })); + }; + + const handleChange = (newWeight: number) => { + setNewWeight(newWeight); + setNewAccount((previousValue) => ({ + ...previousValue, + weight: Number((newWeight * 100).toFixed()) })); + }; + + const formattedWeight = (weight: number) =>{ + return Number((weight * 100).toFixed()); + }; + + return ( + + + + {formattedData.map((data) => ( + + // + // + } + > +
+
+ +
+ + handleWeightChange(data.account.id, weight)} + /> +
+
+ ))} + + {hasNewAccount && ( + { + setHasNewAccount(false); + setNewWeight(0.05); + }} + /> + )} + +
+ {hasNewAccount && } + {!hasNewAccount && } + + + + +
+
+ ); +}; + +export default ManageZapSplit; +export type { INewAccount }; \ No newline at end of file