Skip to content

Commit 8b1e0c1

Browse files
Merge pull request lfglabs-dev#1131 from wheval/domain-expiration
fix domain expiration modal
2 parents 621d1f7 + 2cd7e9e commit 8b1e0c1

File tree

3 files changed

+264
-121
lines changed

3 files changed

+264
-121
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React from "react";
2+
import {
3+
Dialog,
4+
DialogTitle,
5+
DialogContent,
6+
DialogActions,
7+
Button,
8+
} from "@mui/material";
9+
import CloseIcon from "@/components/UI/iconsComponents/icons/closeIcon";
10+
11+
interface DomainExpiredModalProps {
12+
open: boolean;
13+
onClose: () => void;
14+
onRenew: () => void;
15+
}
16+
17+
const DomainExpiredModal: React.FC<DomainExpiredModalProps> = ({
18+
open,
19+
onClose,
20+
onRenew,
21+
}) => {
22+
return (
23+
<Dialog
24+
open={open}
25+
onClose={onClose}
26+
fullWidth
27+
PaperProps={{
28+
style: {
29+
borderRadius: "16px",
30+
padding: "24px 48px",
31+
maxWidth: "690px",
32+
},
33+
}}
34+
>
35+
<DialogTitle
36+
sx={{
37+
fontFamily: "QuickZap",
38+
color: "#454545",
39+
textAlign: "center",
40+
fontSize: "24px",
41+
fontWeight: "400",
42+
position: "relative",
43+
paddingBottom: "4px",
44+
}}
45+
>
46+
Domain Expiration Notice
47+
</DialogTitle>
48+
<DialogContent>
49+
<div className="px-2">
50+
<p className="text-center font-normal text-[14px] leading-[24px] text-[#8C8989]">
51+
Your domain has expired. Would you like to renew it now to keep your website active?
52+
</p>
53+
</div>
54+
</DialogContent>
55+
<DialogActions sx={{ justifyContent: "center", gap: 2, pb: 4 }}>
56+
<Button
57+
sx={{
58+
fontFamily: "QuickZap",
59+
textAlign: "center",
60+
fontWeight: "400",
61+
fontSize: "14px",
62+
border: "2px solid #19AA6E",
63+
borderRadius: "8px",
64+
padding: "10px 16px",
65+
backgroundColor: "#0C8654 !important",
66+
color: "white",
67+
}}
68+
onClick={onRenew}
69+
className=""
70+
>
71+
Renew Domain
72+
</Button>
73+
</DialogActions>
74+
<div className="absolute cursor-pointer right-6 top-6" onClick={onClose}>
75+
<CloseIcon />
76+
</div>
77+
</Dialog>
78+
);
79+
};
80+
81+
export default DomainExpiredModal;

components/identities/availableIdentities.tsx

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useMemo, useState } from "react";
1+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import styles from "../../styles/components/identitiesV1.module.css";
33
import { useRouter } from "next/router";
44
import IdentityCard from "../../components/identities/identityCard";
@@ -18,8 +18,11 @@ import IdentityActionsSkeleton from "@/components/identities/skeletons/identityA
1818
import { hexToDecimal } from "@/utils/feltService";
1919
import WalletConnect from "@/components/UI/walletConnect";
2020
import { Connector } from "starknetkit";
21-
import { FaPlus } from "react-icons/fa";
21+
import { FaCircle, FaPlus } from "react-icons/fa";
2222
import IdentitiesSkeleton from "./skeletons/identitiesSkeleton";
23+
import { Tooltip } from "@mui/material";
24+
import { isIdentityExpired } from "../../utils/dateService";
25+
import DomainExpiredModal from "@/components/UI/domainExpiredModal";
2326

2427
const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
2528
const router = useRouter();
@@ -43,6 +46,9 @@ const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
4346
const randomTokenId: number = Math.floor(Math.random() * 1000000000000);
4447
const [showWalletConnectModal, setShowWalletConnectModal] =
4548
useState<boolean>(false);
49+
const [domainExpiredModalOpen, setDomainExpiredModalOpen] = useState(false);
50+
const [selectedExpiredDomain, setSelectedExpiredDomain] = useState<FullId | null>(null);
51+
const hasOpenedModal = useRef(false);
4652

4753
const callData = useMemo(() => {
4854
return {
@@ -159,6 +165,26 @@ const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
159165
}
160166
}, [address, router.asPath]);
161167

168+
const isCurrentIdentityExpired = useMemo(() => {
169+
if (!identity || !isIdentityADomain) return false;
170+
return identity?.domainExpiry
171+
? new Date(identity.domainExpiry * 1000) < new Date()
172+
: false;
173+
}, [identity, isIdentityADomain]);
174+
175+
useEffect(() => {
176+
if (isCurrentIdentityExpired && isOwner && !domainExpiredModalOpen && identity && !hasOpenedModal.current) {
177+
setSelectedExpiredDomain({
178+
id: tokenId,
179+
domain: identity.domain,
180+
domain_expiry: identity.domainExpiry
181+
} as FullId);
182+
setDomainExpiredModalOpen(true);
183+
hasOpenedModal.current = true;
184+
}
185+
}, [isCurrentIdentityExpired, isOwner, domainExpiredModalOpen, identity, tokenId, selectedExpiredDomain]);
186+
187+
162188
const connectWallet = async (connector: Connector) => {
163189
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
164190
// @ts-ignore
@@ -178,26 +204,50 @@ const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
178204
<div
179205
className={`${styles.IDScreen} px-[16px] lg:px-0 overflow-x-hidden flex flex-col xl:flex-row justify-center items-center gap-[24px] `}
180206
>
181-
<div className=" w-[100%] sm:w-[358px] xl:w-[220px]">
182-
{ownedIdentities.length !== 1 && (
207+
{/* LEFT SIDE NAV */}
208+
<div className=" w-[100%] sm:w-[358px] xl:min-w-[220px] xl:w-fit xl:max-w-[310px]">
209+
{ownedIdentities.length !== 0 && (
183210
<div
184211
className={`
185212
${styles.sideNav} border w-[100%] md:w-auto h-[319px] xl:h-auto relative flex flex-col items-center justify-between sm:px-[24px] md:pt-[24px] m-auto shadow-sm rounded-2xl `}
186213
>
187214
<div className="h-full md:min-h-[80%] w-full overflow-y-auto hide-scrollbar flex flex-col gap-[2px] ">
188215
{ownedIdentities.map((domain, index) => (
189-
<button
190-
className={`${
191-
domain.id === router.query.tokenId ||
192-
domain.id === tokenId
193-
? "text-[#402D28]"
194-
: " text-[#CDCCCC] hover:text-[#402D28]"
195-
} font-medium text-lg sm:text-md lg:text-lg leading-5 cursor-pointer border-[#4545451A] border-b-[1px] md:border-none md:py-0 py-6 md:my-3 block w-full text-center xl:text-left`}
196-
key={index}
197-
onClick={() => router.push(`/identities/${domain.id}`)}
198-
>
199-
{domain.domain ? domain.domain : domain.id}
200-
</button>
216+
<div key={index} className="flex w-full items-center justify-start gap-1">
217+
<button
218+
className={`${
219+
domain.id === router.query.tokenId ||
220+
domain.id === tokenId
221+
? "text-[#402D28]"
222+
: " text-[#CDCCCC] font-normal hover:text-[#402D28]"
223+
} font-bold text-lg sm:text-md lg:text-md leading-5 cursor-pointer transition-all duration-300 border-[#4545451A] border-b-[1px] md:border-none md:py-0 py-6 md:my-3 block w-fit text-center xl:text-left`}
224+
key={index}
225+
onClick={() => {
226+
router.push(`/identities/${domain.id}`);
227+
if (isIdentityExpired(domain)) {
228+
setSelectedExpiredDomain(domain);
229+
setDomainExpiredModalOpen(true);
230+
}}}
231+
>
232+
{domain.domain ? domain.domain : domain.id}
233+
</button>
234+
{isIdentityExpired(domain) && (
235+
<Tooltip
236+
title="Domain Expired"
237+
componentsProps={{
238+
tooltip: {
239+
sx: {
240+
bgcolor: "#402D28",
241+
},
242+
},
243+
}}
244+
>
245+
<div className="flex w-[16px] h-[16px] items-center justify-center">
246+
<FaCircle className="text-red-500 text-[8px] ml-1" />
247+
</div>
248+
</Tooltip>
249+
)}
250+
</div>
201251
))}
202252
</div>
203253
<button
@@ -214,6 +264,7 @@ const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
214264
</div>
215265
)}
216266
</div>
267+
{/* MAIN CARD */}
217268
<div
218269
className={` flex justify-center items-center ${styles.CardContainer}`}
219270
>
@@ -225,6 +276,7 @@ const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
225276
ppImageUrl={ppImageUrl}
226277
/>
227278
</div>
279+
{/* RIGHT SIDE ACTIONS */}
228280
<div className=" min-w-[280px]">
229281
{hideActions ? (
230282
minting && <IdentityActionsSkeleton />
@@ -247,6 +299,16 @@ const AvailableIdentities = ({ tokenId }: { tokenId: string }) => {
247299
/>
248300
)}
249301
</div>
302+
<DomainExpiredModal
303+
open={domainExpiredModalOpen}
304+
onClose={() => {
305+
setDomainExpiredModalOpen(false);
306+
}}
307+
onRenew={() => {
308+
setDomainExpiredModalOpen(false);
309+
router.push("/renewal");
310+
}}
311+
/>
250312
<TxConfirmationModal
251313
txHash={ppTxHash}
252314
isTxModalOpen={isTxModalOpen}

0 commit comments

Comments
 (0)