Merged develop into feature-payment-corporate-id
This commit is contained in:
@@ -62,28 +62,21 @@ const columnHelper = createColumnHelper<Payment>();
|
||||
|
||||
const PaymentCreator = ({onClose, reload, showComission = false}: {onClose: () => void; reload: () => void; showComission: boolean}) => {
|
||||
const [corporate, setCorporate] = useState<CorporateUser>();
|
||||
const [price, setPrice] = useState<number>(0);
|
||||
const [currency, setCurrency] = useState<string>("EUR");
|
||||
const [commission, setCommission] = useState<number>(0);
|
||||
const [referralAgent, setReferralAgent] = useState<AgentUser>();
|
||||
const [date, setDate] = useState<Date>(new Date());
|
||||
|
||||
const {users} = useUsers();
|
||||
|
||||
useEffect(() => {
|
||||
if (!corporate) return setReferralAgent(undefined);
|
||||
if (!corporate.corporateInformation?.referralAgent) return setReferralAgent(undefined);
|
||||
const price = corporate?.corporateInformation?.payment?.value || 0;
|
||||
const commission = corporate?.corporateInformation?.payment?.commission || 0;
|
||||
const currency = corporate?.corporateInformation?.payment?.currency || 'EUR';
|
||||
|
||||
const referralAgent = users.find((u) => u.id === corporate.corporateInformation.referralAgent);
|
||||
setReferralAgent(referralAgent as AgentUser | undefined);
|
||||
}, [corporate, users]);
|
||||
const referralAgent = useMemo(() => {
|
||||
if(corporate?.corporateInformation?.referralAgent) {
|
||||
return users.find((u) => u.id === corporate.corporateInformation.referralAgent);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const payment = corporate?.corporateInformation?.payment;
|
||||
|
||||
setPrice(payment?.value || 0);
|
||||
setCurrency(payment?.currency || "EUR");
|
||||
}, [corporate]);
|
||||
return undefined;
|
||||
}, [corporate?.corporateInformation?.referralAgent, users]);
|
||||
|
||||
const submit = () => {
|
||||
axios
|
||||
@@ -91,7 +84,7 @@ const PaymentCreator = ({onClose, reload, showComission = false}: {onClose: () =
|
||||
corporate: corporate?.id,
|
||||
agent: referralAgent?.id,
|
||||
agentCommission: commission,
|
||||
agentValue: toFixedNumber((commission / 100) * price, 2),
|
||||
agentValue: toFixedNumber((commission! / 100) * price!, 2),
|
||||
currency,
|
||||
value: price,
|
||||
isPaid: false,
|
||||
@@ -146,16 +139,18 @@ const PaymentCreator = ({onClose, reload, showComission = false}: {onClose: () =
|
||||
<div className="w-full grid grid-cols-5 gap-2">
|
||||
<Input
|
||||
name="paymentValue"
|
||||
onChange={(e) => setPrice(e ? parseInt(e) : 0)}
|
||||
onChange={() => {}}
|
||||
type="number"
|
||||
value={price}
|
||||
defaultValue={0}
|
||||
className="col-span-3"
|
||||
disabled
|
||||
/>
|
||||
<Select
|
||||
className="px-4 col-span-2 py-4 w-full text-sm font-normal placeholder:text-mti-gray-cool disabled:bg-mti-gray-platinum/40 disabled:text-mti-gray-dim disabled:cursor-not-allowed bg-white rounded-full border border-mti-gray-platinum focus:outline-none"
|
||||
options={CURRENCIES.map(({label, currency}) => ({value: currency, label}))}
|
||||
defaultValue={{value: currency || "EUR", label: CURRENCIES.find((c) => c.currency === currency)?.label || "Euro"}}
|
||||
onChange={(value) => setCurrency(value?.value || "EUR")}
|
||||
onChange={() => {}}
|
||||
value={{value: currency || "EUR", label: CURRENCIES.find((c) => c.currency === currency)?.label || "Euro"}}
|
||||
styles={{
|
||||
control: (styles) => ({
|
||||
@@ -173,6 +168,7 @@ const PaymentCreator = ({onClose, reload, showComission = false}: {onClose: () =
|
||||
color: state.isFocused ? "black" : styles.color,
|
||||
}),
|
||||
}}
|
||||
isDisabled
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -180,13 +176,20 @@ const PaymentCreator = ({onClose, reload, showComission = false}: {onClose: () =
|
||||
<div className="flex gap-4 w-full">
|
||||
<div className="flex flex-col w-full gap-3">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Commission *</label>
|
||||
<Input name="commission" onChange={(e) => setCommission(e ? parseInt(e) : 0)} type="number" defaultValue={0} />
|
||||
<Input
|
||||
name="commission"
|
||||
onChange={() => {}}
|
||||
type="number"
|
||||
defaultValue={0}
|
||||
value={commission}
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col w-full gap-3">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Commission Value*</label>
|
||||
<Input
|
||||
name="commissionValue"
|
||||
value={`${(commission / 100) * price} ${CURRENCIES.find((c) => c.currency === currency)?.label}`}
|
||||
value={`${(commission! / 100) * price!} ${CURRENCIES.find((c) => c.currency === currency)?.label}`}
|
||||
onChange={() => null}
|
||||
type="text"
|
||||
defaultValue={0}
|
||||
|
||||
Reference in New Issue
Block a user