Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | 1x 55x 55x 55x 55x 55x 55x 55x 55x 10x 55x 55x 55x 55x 55x 15x 18x | import NiceModal from "@ebay/nice-modal-react";
import { Skeleton, Stack } from "@mui/material";
import HFGiveSelect from "@shared/HFInputs/HFGiveSelect/HFGiveSelect";
import GiveText from "@shared/Text/GiveText";
import { addSizeToImage } from "@utils/image.helpers";
import { parseAmount, toEnFormat } from "@utils/index";
import { useEffect } from "react";
import { useFormContext } from "react-hook-form";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import HFGiveCustomAmount from "@shared/HFInputs/HFGiveCustomAmount/HFGiveCustomAmount";
import { MAX_AMOUNT_TARGET } from "@constants/constants";
import { useAppTheme } from "@theme/v2/Provider";
import { HFCheckbox } from "@shared/HFInputs/HFGiveCheckbox/HFGiveCheckbox";
import { TERMS_OF_SERVICE_MODAL } from "modals/modal_names";
import FeeSection from "./FeeSection";
import { GiveSelectOption } from "@shared/GiveInputs/GiveSelect";
import GiveThumbnail from "@shared/Thumbnail/GiveThumbnail";
import { checkPortals } from "@utils/routing";
import HFGiveSwitch from "@shared/HFInputs/HFGiveSwitch/HFGiveSwitch";
import {
buildAcquirerBalanceInfo,
calculateBpsFee,
getAmountAsNumber,
} from "./helpers";
import ProcessorBalanaceItem from "./ProcessorBalanceItem";
import { WarningOctagonIcon } from "@phosphor-icons/react";
import { BalanceDataType } from "@features/MerchantPortal/ManageMoney/hooks/useBalances";
import { useGetCurrentMerchantId } from "@hooks/common";
type Props = {
balance: number;
imageURL: string;
newBalance: number;
totalAmount: number;
bankAccountList: GiveSelectOption[];
isLoadingBankAccounts: boolean;
fees: string;
selectedBankAccount: string;
reserveFunds?: number;
minimumReserveBPS?: number;
processorBalances?: BalanceDataType[];
isLoadingBalances?: boolean;
isPayfac?: boolean;
};
const SendMoneyStep = ({
balance,
imageURL,
newBalance,
bankAccountList,
isLoadingBankAccounts,
fees,
totalAmount,
selectedBankAccount,
reserveFunds,
minimumReserveBPS,
processorBalances,
isLoadingBalances,
isPayfac,
}: Props) => {
const { palette } = useAppTheme();
const { isMobileView } = useCustomThemeV2();
const { isMerchantPortal, isAcquirerManageMoney } = checkPortals();
const { isAdminOrOwner } = useGetCurrentMerchantId();
const {
watch,
setValue,
formState: { errors },
} = useFormContext();
const values = watch();
const isWorldpayPayfac = isPayfac && values.processor === "worldpay";
useEffect(() => {
Iif (isWorldpayPayfac) {
const defaultAccount = bankAccountList.find((a: any) => a.isDefault);
if (defaultAccount) {
setValue("account", defaultAccount.value, { shouldValidate: true });
}
}
}, [isWorldpayPayfac]);
const thumbnailType = isMerchantPortal ? "merchant" : "provider";
const showReserve = Boolean(
minimumReserveBPS && reserveFunds !== undefined && isMerchantPortal,
);
const minimumReserveBPSFee = minimumReserveBPS
? calculateBpsFee(
getAmountAsNumber(values.amount),
minimumReserveBPS,
reserveFunds || 0,
)
: undefined;
const processorBalanaceList = buildAcquirerBalanceInfo({
processorBalances,
});
return (
<>
<Stack direction="row" alignItems="center" spacing={2}>
<GiveThumbnail
imageUrl={imageURL ? addSizeToImage(imageURL, "medium") : ""}
size="medium"
type={thumbnailType}
/>
<Stack
direction="row"
justifyContent="space-between"
alignItems="center"
width="100%"
>
<Stack flex={1}>
{isLoadingBalances ? (
<Skeleton variant="text" width="40%" height="40px" />
) : (
<GiveText variant="h4">{toEnFormat(balance)}</GiveText>
)}
<GiveText variant="bodyS" color="secondary">
Available Balance (USD)
</GiveText>
</Stack>
{showReserve && (
<Stack flex={1}>
<GiveText variant="h4">{toEnFormat(reserveFunds)}</GiveText>
<GiveText variant="bodyS" color="secondary">
Reserve Funds (USD)
</GiveText>
</Stack>
)}
</Stack>
</Stack>
{!!processorBalanaceList && (
<Stack gap="12px">
{processorBalanaceList.map((item) => (
<ProcessorBalanaceItem {...item} key={item.label} />
))}
{errors?.processor && (
<Stack gap="8px" direction="row" alignItems="center">
<WarningOctagonIcon
size={24}
color={palette.primitive?.error[50]}
/>
<GiveText variant="bodyS" color="error1">
{errors.processor.message?.toString()}
</GiveText>
</Stack>
)}
</Stack>
)}
<HFGiveSelect
isFetchindData={isLoadingBankAccounts}
name="account"
label="Send To"
placeholder="Select a recipient"
options={bankAccountList || []}
disabled={isWorldpayPayfac}
renderValue={() => selectedBankAccount}
useContextualMenu
contextualMenuProps={{
showEmptySectionWhenNoData: true,
emptySection: "no-bank-accounts",
...(!isMobileView
? {
color: "tertiary",
texture: "blurred",
menuWidth: 600,
}
: {}),
}}
data-testid="business-type"
/>
<HFGiveCustomAmount
name="amount"
label="Amount to Send"
placeholder="Amount"
hidePlaceholder
bounded={true}
max={Number(MAX_AMOUNT_TARGET)}
currency="usd"
min={0}
initialValue=""
helper={
errors?.amount || !values.amount ? undefined : (
<GiveText variant="bodyXS" color="secondary" mt={0.5}>
Remaining available balance will be{" "}
<span style={{ color: palette?.text?.primary }}>
{parseAmount(newBalance)?.replace("-", "")} USD
</span>
</GiveText>
)
}
/>
{isAcquirerManageMoney && isAdminOrOwner && (
<Stack direction="row" spacing="12px" alignItems="flex-start">
<HFGiveSwitch name="isManual" />
<Stack>
<GiveText variant="bodyS">Manual Transfer</GiveText>
<GiveText variant="bodyXS" color="secondary">
When enabled, this transfer will not be included in the ACH/Batch
file and will be marked as settled immediately.
</GiveText>
</Stack>
</Stack>
)}
{!isAcquirerManageMoney && (
<>
<FeeSection
fees={fees}
newBalance={
minimumReserveBPSFee
? totalAmount + minimumReserveBPSFee
: totalAmount
}
minimumReserveBPSFee={
minimumReserveBPS ? parseAmount(minimumReserveBPSFee) : undefined
}
/>
<HFCheckbox
size="medium"
data-testid="agree-tos-checkbox"
name="agree"
label={
<>
I agree to GivePayments’{" "}
<span
style={{ textDecoration: "underline", cursor: "pointer" }}
onClick={() => NiceModal.show(TERMS_OF_SERVICE_MODAL)}
>
Terms of Service
</span>
</>
}
/>
</>
)}
</>
);
};
export default SendMoneyStep;
|