Skip to content

Commit 8089248

Browse files
authored
feat: style DeleteDialog for expired names (#472)
* style delete dialog * fix disabled button * rename constnat * fmt
1 parent 3172428 commit 8089248

File tree

1 file changed

+67
-30
lines changed

1 file changed

+67
-30
lines changed

dapp/src/components/dialogs/DeleteNameDialog.tsx

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@
33

44
'use client';
55

6-
import { Info } from '@iota/apps-ui-icons';
6+
import { Warning } from '@iota/apps-ui-icons';
77
import {
88
Button,
9+
ButtonType,
910
Dialog,
1011
DialogBody,
1112
DialogContent,
13+
DialogPosition,
1214
Header,
1315
InfoBox,
1416
InfoBoxStyle,
1517
InfoBoxType,
1618
LoadingIndicator,
19+
Panel,
1720
} from '@iota/apps-ui-kit';
1821
import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '@iota/dapp-kit';
1922
import { isSubname } from '@iota/iota-names-sdk';
2023
import { useMutation, useQueryClient } from '@tanstack/react-query';
24+
import { useEffect, useState } from 'react';
2125

2226
import { useRegistrationNfts } from '@/hooks';
2327
import { queryKey } from '@/hooks/queryKey';
2428
import { NameUpdate, useUpdateNameTransaction } from '@/hooks/useUpdateNameTransaction';
2529
import { RegistrationNft } from '@/lib/interfaces/registration.interfaces';
30+
import { formatNameLabel } from '@/lib/utils/format/formatNames';
2631
import { getNameObject } from '@/lib/utils/names';
2732

2833
type DeleteNameDialogProps = {
@@ -37,6 +42,8 @@ export function DeleteNameDialog({ nft, setOpen }: DeleteNameDialogProps) {
3742

3843
const { data: subnamesOwned } = useRegistrationNfts('subname');
3944

45+
const [deleteSeconds, setDeleteSeconds] = useState(5);
46+
4047
const isNameSubname = nft ? isSubname(nft.name) : null;
4148

4249
// Create updates
@@ -65,7 +72,7 @@ export function DeleteNameDialog({ nft, setOpen }: DeleteNameDialogProps) {
6572
const { mutateAsync: signAndExecuteTransaction, isPending: isSendingTransaction } =
6673
useSignAndExecuteTransaction();
6774

68-
const { mutate: save, isPending: isSaving } = useMutation({
75+
const { mutate: deleteName, isPending: isSaving } = useMutation({
6976
async mutationFn() {
7077
if (!updateNameTransaction) return;
7178
const transaction = await signAndExecuteTransaction({
@@ -89,40 +96,70 @@ export function DeleteNameDialog({ nft, setOpen }: DeleteNameDialogProps) {
8996

9097
const isLoading = isLoadingUpdateNameTransaction || isSaving || isSendingTransaction;
9198
const disableDeleteButton = isLoadingUpdateNameTransaction || isLoading || !nft.isExpired;
99+
const deleteActionNotAllowed = deleteSeconds > 0;
100+
useEffect(() => {
101+
if (!deleteActionNotAllowed) return;
102+
103+
const id = setInterval(() => {
104+
setDeleteSeconds((s) => s - 1);
105+
}, 1_000);
106+
107+
return () => clearInterval(id);
108+
}, [deleteActionNotAllowed]);
92109

93110
return (
94111
<Dialog open onOpenChange={setOpen}>
95-
<DialogContent containerId="overlay-portal-container" isFixedPosition>
96-
<Header title={`Delete ${nft.name}`} onClose={closeDialog} titleCentered />
112+
<DialogContent containerId="overlay-portal-container" position={DialogPosition.Right}>
113+
<Header title="Delete" onClose={closeDialog} />
97114
<DialogBody>
98-
<div className="flex flex-col gap-y-md">
99-
{nft.isExpired && !isLoading ? (
100-
<InfoBox
101-
title={`${nft.name} is expired`}
102-
supportingText="This name is expired and can be deleted."
103-
icon={<Info />}
104-
type={InfoBoxType.Warning}
105-
style={InfoBoxStyle.Elevated}
115+
<div className="flex flex-col justify-between h-full items-center">
116+
<div className="flex flex-col w-full gap-y-md">
117+
<div className="flex flex-col items-start gap-y-md">
118+
<p className="text-title-md text-names-neutral-100">
119+
Are you sure you want to delete this name?
120+
</p>
121+
<Panel bgColor="bg-names-neutral-12">
122+
<div className="p-md">
123+
<span className="text-names-neutral-100 text-headline-sm">
124+
{formatNameLabel(nft.name)}
125+
</span>
126+
</div>
127+
</Panel>
128+
<InfoBox
129+
type={InfoBoxType.Warning}
130+
style={InfoBoxStyle.Default}
131+
icon={<Warning />}
132+
title="Permanently remove name"
133+
supportingText="This action is irreversible and will permanently remove your ownership of the name"
134+
/>
135+
</div>
136+
137+
{updateNameError ? (
138+
<p className="text-error-30 dark:text-error-70 text-center">
139+
{updateNameError.message}
140+
</p>
141+
) : null}
142+
</div>
143+
<div className="flex w-full flex-row gap-x-xs mt-xs">
144+
<Button
145+
type={ButtonType.Secondary}
146+
text="Cancel"
147+
onClick={closeDialog}
148+
fullWidth
149+
/>
150+
<Button
151+
icon={isLoading ? <LoadingIndicator /> : null}
152+
text={
153+
deleteActionNotAllowed
154+
? `Delete in ${deleteSeconds}s`
155+
: 'Delete'
156+
}
157+
disabled={disableDeleteButton || deleteActionNotAllowed}
158+
type={ButtonType.Destructive}
159+
onClick={() => deleteName()}
160+
fullWidth
106161
/>
107-
) : null}
108-
109-
<div className="flex flex-col gap-y-xs items-center">
110-
<p className="text-body-md">
111-
Are you sure you want to delete this name?
112-
</p>
113-
<p>This action cannot be undone</p>
114162
</div>
115-
{updateNameError ? (
116-
<p className="text-error-30 dark:text-error-70 text-center">
117-
{updateNameError.message}
118-
</p>
119-
) : null}
120-
<Button
121-
icon={isLoading ? <LoadingIndicator /> : null}
122-
text="Delete Name"
123-
disabled={disableDeleteButton}
124-
onClick={() => save()}
125-
/>
126163
</div>
127164
</DialogBody>
128165
</DialogContent>

0 commit comments

Comments
 (0)