setSelectedAccountId(account.id)}>
-
+
+ account.type !== AccountType.Shared && setSelectedAccountId(account.id)
+ }
+ >
+
))}
diff --git a/web/src/views/Cards/components/BankCards.tsx b/web/src/views/Cards/components/BankCards.tsx
index a607a5ae..97351f57 100644
--- a/web/src/views/Cards/components/BankCards.tsx
+++ b/web/src/views/Cards/components/BankCards.tsx
@@ -136,6 +136,7 @@ const BankCards = ({ onSelectCardId, selectedCardId, accountId }: BankCardsProps
};
const selectedAccount = accounts.find((acc) => acc.id === selectedAccountId);
+ const selectedCard = cards.find((card) => card.id === selectedCardId);
const isAffordable = (selectedAccount?.balance ?? 0) > cost;
return (
@@ -180,11 +181,16 @@ const BankCards = ({ onSelectCardId, selectedCardId, accountId }: BankCardsProps
{Boolean(selectedCardId) && (
{
updateCards(accountId);
onSelectCardId(0);
}}
+ onDelete={() => {
+ updateCards(accountId);
+ onSelectCardId(0);
+ }}
/>
)}
diff --git a/web/src/views/Cards/components/CardActions.tsx b/web/src/views/Cards/components/CardActions.tsx
index 798af02d..4ac9904b 100644
--- a/web/src/views/Cards/components/CardActions.tsx
+++ b/web/src/views/Cards/components/CardActions.tsx
@@ -7,7 +7,6 @@ import {
DialogContentText,
DialogTitle,
Stack,
- Typography,
} from '@mui/material';
import { Heading1 } from '@components/ui/Typography/Headings';
import { PreHeading } from '@components/ui/Typography/BodyText';
@@ -16,33 +15,30 @@ import BaseDialog from '@components/Modals/BaseDialog';
import { fetchNui } from '@utils/fetchNui';
import { CardEvents } from '@typings/Events';
import { CheckRounded, ErrorRounded, InfoRounded } from '@mui/icons-material';
-import { BlockCardInput, UpdateCardPinInput } from '@typings/BankCard';
+import { BlockCardInput, DeleteCardInput, UpdateCardPinInput } from '@typings/BankCard';
import PinField from '@components/ui/Fields/PinField';
interface CardActionsProps {
cardId: number;
+ isBlocked?: boolean;
onBlock?(): void;
+ onDelete?(): void;
}
-const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
+const CardActions = ({ cardId, onBlock, onDelete, isBlocked }: CardActionsProps) => {
const [error, setError] = useState('');
const [success, setSuccess] = useState('');
const [isLoading, setIsLoading] = useState(false);
- const [isUpdatingPin, setIsUpdatingPin] = useState(false);
- const [isBlockingCard, setIsBlockingCard] = useState(false);
- const [pin, setPin] = useState('');
- const [oldPin, setOldPin] = useState('');
+ const [dialog, setDialog] = useState<'none' | 'block' | 'update' | 'delete'>('none');
const [newPin, setNewPin] = useState('');
const [confirmNewPin, setConfirmNewPin] = useState('');
const { t } = useTranslation();
const handleClose = () => {
setIsLoading(false);
- setIsUpdatingPin(false);
- setIsBlockingCard(false);
+ setDialog('none');
setError('');
setNewPin('');
- setOldPin('');
setConfirmNewPin('');
setTimeout(() => {
@@ -58,7 +54,6 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
await fetchNui
(CardEvents.Block, {
cardId,
- pin: parseInt(pin, 10),
});
setSuccess(t('Successfully blocked the card.'));
handleClose();
@@ -72,6 +67,27 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
setIsLoading(false);
};
+ const handleDeleteCard = async () => {
+ try {
+ setSuccess('');
+ setError('');
+ setIsLoading(true);
+
+ await fetchNui(CardEvents.Delete, {
+ cardId,
+ });
+ setSuccess(t('Successfully deleted the card.'));
+ handleClose();
+ onDelete?.();
+ } catch (err: unknown | Error) {
+ if (err instanceof Error) {
+ setError(err.message);
+ }
+ }
+
+ setIsLoading(false);
+ };
+
const handleUpdatePin = async () => {
try {
setError('');
@@ -83,7 +99,7 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
}
setIsLoading(true);
- const data = { cardId, newPin: parseInt(newPin, 10), oldPin: parseInt(oldPin, 10) };
+ const data = { cardId, newPin: parseInt(newPin, 10) };
await fetchNui(CardEvents.UpdatePin, data);
setSuccess(t('Successfully updated pin.'));
@@ -107,10 +123,18 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
-
-
{success && (
@@ -121,16 +145,11 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
-
+
{t('Update pin')}
- setOldPin(event.target.value)}
- />
{
-
+
{t('Blocking card')}
@@ -172,12 +191,6 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
{t('Are you sure you want to block this card? This action cannot be undone.')}
- {t('Enter card pin to block the card.')}
- setPin(event.target.value)}
- />
{error && (
@@ -200,6 +213,37 @@ const CardActions = ({ cardId, onBlock }: CardActionsProps) => {
+
+
+ {t('Deleting card')}
+
+
+
+
+ {t('Are you sure you want to delete this card? This action cannot be undone.')}
+
+
+
+ {error && (
+ : }
+ color={isLoading ? 'info' : 'error'}
+ >
+ {error}
+
+ )}
+
+
+
+
+
+ {t('Cancel')}
+
+
+ {t('Delete the card')}
+
+
+
>
);
};