* Icon and IconName * Button and ButtonGroup * UserAvatar * AvatarGroup * Avatar * WizardLayout * Dialogs * EmptyScreen * showToast and TextField * Editor * Skeleton * Skeleton * TopBanner and showToast * Button again * more * perf: Remove app-store reference from @calcom/ui * more * Fixing types * Icon * Fixed casing * dropdown * more * Select * more * Badge * List * more * Divider * more * fix * fix type check * refactor * fix * fix * fix * fix * fix * fix * fix * fix type check * fix * fix * fix * fix * more * more * more * more * add index file to components/command * fix * fix * fix * fix imports * fix * fix * fix * fix * fix * fix * fix * fix build errors * fix build errors * fix --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
import type { Dispatch, SetStateAction } from "react";
|
|
import { useState } from "react";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogClose } from "@calcom/ui/components/dialog";
|
|
import { Icon } from "@calcom/ui/components/icon";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
interface IRescheduleDialog {
|
|
isOpenDialog: boolean;
|
|
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
|
|
bookingId: number;
|
|
paymentAmount: number;
|
|
paymentCurrency: string;
|
|
}
|
|
|
|
export const ChargeCardDialog = (props: IRescheduleDialog) => {
|
|
const { t } = useLocale();
|
|
const utils = trpc.useUtils();
|
|
const { isOpenDialog, setIsOpenDialog, bookingId } = props;
|
|
const [chargeError, setChargeError] = useState(false);
|
|
const chargeCardMutation = trpc.viewer.payments.chargeCard.useMutation({
|
|
onSuccess: () => {
|
|
utils.viewer.bookings.invalidate();
|
|
setIsOpenDialog(false);
|
|
showToast("Charge successful", "success");
|
|
},
|
|
onError: () => {
|
|
setChargeError(true);
|
|
},
|
|
});
|
|
|
|
const currencyStringParams = {
|
|
amount: props.paymentAmount / 100.0,
|
|
formatParams: { amount: { currency: props.paymentCurrency } },
|
|
};
|
|
|
|
return (
|
|
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
|
<DialogContent>
|
|
<div className="flex flex-row space-x-3">
|
|
<div className=" bg-subtle flex h-10 w-10 flex-shrink-0 justify-center rounded-full">
|
|
<Icon name="credit-card" className="m-auto h-6 w-6" />
|
|
</div>
|
|
<div className="pt-1">
|
|
<DialogHeader title={t("charge_card")} />
|
|
<p>{t("charge_card_dialog_body", currencyStringParams)}</p>
|
|
|
|
{chargeError && (
|
|
<div className="mt-4 flex text-red-500">
|
|
<Icon name="triangle-alert" className="mr-2 h-5 w-5 " aria-hidden="true" />
|
|
<p className="text-sm">{t("error_charging_card")}</p>
|
|
</div>
|
|
)}
|
|
|
|
<DialogFooter>
|
|
<DialogClose />
|
|
<Button
|
|
data-testid="send_request"
|
|
disabled={chargeCardMutation.isPending || chargeError}
|
|
onClick={() =>
|
|
chargeCardMutation.mutate({
|
|
bookingId,
|
|
})
|
|
}>
|
|
{t("charge_attendee", currencyStringParams)}
|
|
</Button>
|
|
</DialogFooter>
|
|
</div>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|