feat(SW-245): Delete credit card
This commit is contained in:
committed by
Michael Zetterberg
parent
2af17ef4d8
commit
e9a6499086
40
components/Profile/DeleteCreditCardButton/index.tsx
Normal file
40
components/Profile/DeleteCreditCardButton/index.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import { Delete } from "@/components/Icons"
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||||
|
||||
export default function DeleteCreditCardButton({
|
||||
creditCardId,
|
||||
}: {
|
||||
creditCardId: string
|
||||
}) {
|
||||
const { formatMessage } = useIntl()
|
||||
const trpcUtils = trpc.useUtils()
|
||||
|
||||
const deleteCreditCardMutation = trpc.user.creditCard.delete.useMutation({
|
||||
onSuccess() {
|
||||
trpcUtils.user.creditCards.invalidate()
|
||||
toast.success(formatMessage({ id: "Credit card deleted successfully" }))
|
||||
},
|
||||
onError() {
|
||||
toast.error(
|
||||
formatMessage({
|
||||
id: "Failed to delete credit card, please try again later.",
|
||||
})
|
||||
)
|
||||
},
|
||||
})
|
||||
async function handleDelete() {
|
||||
deleteCreditCardMutation.mutate({ creditCardId })
|
||||
}
|
||||
return (
|
||||
<Button variant="icon" theme="base" intent="text" onClick={handleDelete}>
|
||||
<Delete color="burgundy" />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user