mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 17:27:16 +00:00
Merge pull request #2782 from Infisical/fix-remove-payment-method
Fix: Resolve Remove Payment Method Error
This commit is contained in:
@@ -52,7 +52,7 @@ export type Invoice = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type PmtMethod = {
|
export type PmtMethod = {
|
||||||
id: string;
|
_id: string;
|
||||||
brand: string;
|
brand: string;
|
||||||
exp_month: number;
|
exp_month: number;
|
||||||
exp_year: number;
|
exp_year: number;
|
||||||
|
|||||||
+34
-7
@@ -1,8 +1,10 @@
|
|||||||
import { faCreditCard, faXmark } from "@fortawesome/free-solid-svg-icons";
|
import { faCreditCard, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { OrgPermissionCan } from "@app/components/permissions";
|
import { OrgPermissionCan } from "@app/components/permissions";
|
||||||
import {
|
import {
|
||||||
|
DeleteActionModal,
|
||||||
EmptyState,
|
EmptyState,
|
||||||
IconButton,
|
IconButton,
|
||||||
Table,
|
Table,
|
||||||
@@ -15,22 +17,41 @@ import {
|
|||||||
Tr
|
Tr
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||||
|
import { usePopUp } from "@app/hooks";
|
||||||
import { useDeleteOrgPmtMethod, useGetOrgPmtMethods } from "@app/hooks/api";
|
import { useDeleteOrgPmtMethod, useGetOrgPmtMethods } from "@app/hooks/api";
|
||||||
|
|
||||||
export const PmtMethodsTable = () => {
|
export const PmtMethodsTable = () => {
|
||||||
const { currentOrg } = useOrganization();
|
const { currentOrg } = useOrganization();
|
||||||
const { data, isLoading } = useGetOrgPmtMethods(currentOrg?.id ?? "");
|
const { data, isLoading } = useGetOrgPmtMethods(currentOrg?.id ?? "");
|
||||||
const deleteOrgPmtMethod = useDeleteOrgPmtMethod();
|
const deleteOrgPmtMethod = useDeleteOrgPmtMethod();
|
||||||
|
const { handlePopUpOpen, handlePopUpClose, handlePopUpToggle, popUp } = usePopUp([
|
||||||
|
"removeCard"
|
||||||
|
] as const);
|
||||||
|
|
||||||
const handleDeletePmtMethodBtnClick = async (pmtMethodId: string) => {
|
const pmtMethodToRemove = popUp.removeCard.data as { id: string; last4: string } | undefined;
|
||||||
if (!currentOrg?.id) return;
|
|
||||||
|
const handleDeletePmtMethodBtnClick = async () => {
|
||||||
|
if (!currentOrg?.id || !pmtMethodToRemove) return;
|
||||||
|
try {
|
||||||
await deleteOrgPmtMethod.mutateAsync({
|
await deleteOrgPmtMethod.mutateAsync({
|
||||||
organizationId: currentOrg.id,
|
organizationId: currentOrg.id,
|
||||||
pmtMethodId
|
pmtMethodId: pmtMethodToRemove.id
|
||||||
});
|
});
|
||||||
|
createNotification({
|
||||||
|
type: "success",
|
||||||
|
text: "Successfully removed payment method"
|
||||||
|
});
|
||||||
|
handlePopUpClose("removeCard");
|
||||||
|
} catch (error: any) {
|
||||||
|
createNotification({
|
||||||
|
type: "error",
|
||||||
|
text: error.message ?? "Error removing payment method"
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<TableContainer className="mt-4">
|
<TableContainer className="mt-4">
|
||||||
<Table>
|
<Table>
|
||||||
<THead>
|
<THead>
|
||||||
@@ -46,7 +67,7 @@ export const PmtMethodsTable = () => {
|
|||||||
{!isLoading &&
|
{!isLoading &&
|
||||||
data &&
|
data &&
|
||||||
data?.length > 0 &&
|
data?.length > 0 &&
|
||||||
data.map(({ id, brand, exp_month, exp_year, funding, last4 }) => (
|
data.map(({ _id: id, brand, exp_month, exp_year, funding, last4 }) => (
|
||||||
<Tr key={`pmt-method-${id}`} className="h-10">
|
<Tr key={`pmt-method-${id}`} className="h-10">
|
||||||
<Td>{brand.charAt(0).toUpperCase() + brand.slice(1)}</Td>
|
<Td>{brand.charAt(0).toUpperCase() + brand.slice(1)}</Td>
|
||||||
<Td>{funding.charAt(0).toUpperCase() + funding.slice(1)}</Td>
|
<Td>{funding.charAt(0).toUpperCase() + funding.slice(1)}</Td>
|
||||||
@@ -59,9 +80,7 @@ export const PmtMethodsTable = () => {
|
|||||||
>
|
>
|
||||||
{(isAllowed) => (
|
{(isAllowed) => (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={async () => {
|
onClick={() => handlePopUpOpen("removeCard", { id, last4 })}
|
||||||
await handleDeletePmtMethodBtnClick(id);
|
|
||||||
}}
|
|
||||||
size="lg"
|
size="lg"
|
||||||
isDisabled={!isAllowed}
|
isDisabled={!isAllowed}
|
||||||
colorSchema="danger"
|
colorSchema="danger"
|
||||||
@@ -86,5 +105,13 @@ export const PmtMethodsTable = () => {
|
|||||||
</TBody>
|
</TBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
<DeleteActionModal
|
||||||
|
isOpen={popUp.removeCard.isOpen}
|
||||||
|
deleteKey="confirm"
|
||||||
|
onChange={(isOpen) => handlePopUpToggle("removeCard", isOpen)}
|
||||||
|
title={`Remove payment method ending in *${pmtMethodToRemove?.last4}?`}
|
||||||
|
onDeleteApproved={handleDeletePmtMethodBtnClick}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user