Skip to content

Commit 02ecbb6

Browse files
committed
Handle network change on parent & member layouts
1 parent 9ae436e commit 02ecbb6

File tree

19 files changed

+657
-230
lines changed

19 files changed

+657
-230
lines changed

app/confirm-email/[token]/page.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import {
1010
Image,
1111
Button,
1212
} from "@chakra-ui/react";
13-
import { usePathname, useRouter } from "next/navigation";
13+
import { usePathname } from "next/navigation";
1414
import jwt from "jsonwebtoken";
1515
import { useEffect, useMemo, useState } from "react";
1616
import { useSignMessage, useAccount } from "wagmi";
1717
import { ethers } from "ethers";
1818
import { CustomConnectButton } from "@/components/ConnectButton";
1919
import { User } from "@/data-schema/types";
2020
import { editUser, getUserByWalletAddress } from "@/services/mongo/routes/user";
21+
import { useAuthStore } from "@/store/auth/authStore";
22+
import shallow from "zustand/shallow";
2123

2224
export default function ConfirmEmail() {
2325
const [isConfirmed, setIsConfirmed] = useState(false);
2426
const [emailVerified, setEmailVerified] = useState(false);
2527
const [disabled, setDisabled] = useState(false);
26-
const [countdown, setCountdown] = useState(5);
2728
const [decodedWalletAddress, setDecodedWalletAddress] = useState<string>("");
2829
const [user, setUser] = useState<User | null>(null);
2930
const [initialUseCheck, setInitialUseCheck] = useState(false);
3031

31-
const router = useRouter();
3232
const pathname = usePathname();
3333

3434
const token = useMemo(() => {
@@ -42,35 +42,14 @@ export default function ConfirmEmail() {
4242

4343
const message = "Confirm Email Address";
4444

45-
const redirectUser = async () => {
46-
let count = 5;
47-
48-
// Countdown function
49-
const countdown = async () => {
50-
if (count === 0) {
51-
router.push("/");
52-
} else {
53-
setTimeout(() => {
54-
count--;
55-
setCountdown(count);
56-
countdown();
57-
}, 1000);
58-
}
59-
};
60-
61-
countdown(); // Start the countdown
62-
};
63-
6445
const updateUserEmailVerified = async (emailVerified: boolean) => {
6546
const body = {
6647
...user,
6748
emailVerified,
6849
};
6950

7051
await editUser(user?.accountId!, body);
71-
7252
setEmailVerified(true);
73-
redirectUser();
7453
};
7554

7655
/*
@@ -155,7 +134,7 @@ export default function ConfirmEmail() {
155134
setUser(user);
156135

157136
if (user.data?.emailVerified) {
158-
redirectUser();
137+
setEmailVerified(true);
159138
}
160139
}
161140
}
@@ -214,7 +193,7 @@ export default function ConfirmEmail() {
214193
Your email address was successfully authenticated.
215194
</Text>
216195
<Text my={5} color="gray" fontSize="lg">
217-
{`Your will be redirected to the DefiKids app in ${countdown} seconds.`}
196+
You may close this window.
218197
</Text>
219198
</Flex>
220199
</Box>
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import { Box } from "@chakra-ui/react";
22
import MemberDashboardClientLayout from "@/components/dashboards/memberDashboard/MemberDashboardClientLayout";
3+
import { getUserByWalletAddress } from "@/services/mongo/routes/user";
4+
import { User } from "@/data-schema/types";
35

46
const getProps = async (context: any) => {
57
const { memberAddress } = context.params || {};
68

9+
const user = await getUserByWalletAddress(memberAddress);
10+
711
return {
8-
memberAddress,
12+
user,
913
};
1014
};
1115

1216
export default async function MemberDashboard(context: any) {
13-
const { memberAddress } = (await getProps(context)) as {
14-
memberAddress: string;
17+
const { user } = (await getProps(context)) as {
18+
user: User;
1519
};
1620

1721
return (
1822
<Box height="100vh">
19-
<MemberDashboardClientLayout memberAddress={memberAddress} />
23+
<MemberDashboardClientLayout user={user} />
2024
</Box>
2125
);
2226
}

app/member-invite/[token]/page.tsx

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,6 @@ const MemberInvite = () => {
118118
}
119119
};
120120

121-
const redirectUser = async () => {
122-
let count = 5;
123-
124-
// Countdown function
125-
const countdown = async () => {
126-
if (count === 0) {
127-
router.push("/");
128-
} else {
129-
setTimeout(() => {
130-
count--;
131-
setCountdown(count);
132-
countdown();
133-
}, 1000);
134-
}
135-
};
136-
137-
countdown(); // Start the countdown
138-
};
139-
140121
const handleToken = async () => {
141122
if (!username) {
142123
toast({
@@ -190,17 +171,6 @@ const MemberInvite = () => {
190171
);
191172
};
192173

193-
// Reset store on page load
194-
useEffect(() => {
195-
reset();
196-
197-
// const init = async () => {
198-
// //@ts-ignore
199-
// const provider = ethers.BrowserProvider(window.ethereum);
200-
// const user = await getUserByWalletAddress(await getSignerAddress());
201-
// set
202-
}, []);
203-
204174
// Check if wallet has already been registered and if invite has already been accepted
205175
useEffect(() => {
206176
if (!decodedData) return;
@@ -231,7 +201,6 @@ const MemberInvite = () => {
231201
await deleteInvitation(invitation._id);
232202

233203
setInviteAccepted(true);
234-
redirectUser();
235204
} catch (error) {
236205
console.error("Error fetching data:", error);
237206
}
@@ -250,8 +219,24 @@ const MemberInvite = () => {
250219
Your account was successfully created.
251220
</Text>
252221
<Text my={5} color="gray" fontSize="lg">
253-
{`Your will be redirected to the DefiKids app in ${countdown} seconds.`}
222+
You may close this window.
254223
</Text>
224+
<Button
225+
mt="3rem"
226+
colorScheme="gray"
227+
size="lg"
228+
style={{
229+
cursor: "pointer",
230+
borderRadius: "10px",
231+
padding: "15px",
232+
}}
233+
onClick={() => {
234+
reset();
235+
router.push(`/member-dashboard/${address}`);
236+
}}
237+
>
238+
<Text fontSize={"lg"}>Go to Dashboard</Text>
239+
</Button>
255240
</Flex>
256241
</Box>
257242
);

next.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3-
experimental: {
4-
appDir: true,
5-
},
3+
// experimental: {
4+
// appDir: true,
5+
// },
66
reactStrictMode: true,
77
images: {
88
domains: ["cryptologos.cc"],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"usehooks-ts": "^2.9.1",
5959
"uuid": "^9.0.0",
6060
"viem": "0.3.35",
61-
"wagmi": "^1.3.10",
61+
"wagmi": "^1.4.12",
6262
"web3": "^4.2.2",
6363
"zustand": "^4.4.0"
6464
},

public/logos/download

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/BFF/mongo/getFamilyMembersByAccount.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const getFamilyMembersByAccount = async (
99
includeParent?: boolean
1010
) => {
1111
const users = (await getAllUsers()) as IUser[];
12-
console.log("getFamilyMembersByAccount", users);
1312
const members = users.filter((user) => {
1413
const checkForParent = () => {
1514
if (includeParent) {

src/components/Auth.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { useEffect } from "react";
55
import { useAuthStore } from "@/store/auth/authStore";
66
import { shallow } from "zustand/shallow";
77
import { watchAccount } from "@wagmi/core";
8-
import { getUserByWalletAddress } from "@/services/mongo/routes/user";
98
import { useRouter } from "next/navigation";
109
import { useAccount } from "wagmi";
11-
import { initialState } from "@/store/auth/createAuthStore";
1210

1311
const Auth = () => {
1412
const router = useRouter();

src/components/AvatarSelection.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,12 @@ export const AvatarSelection = ({
9999
setActiveStep(1);
100100

101101
const avatar = `https://ipfs.io/ipfs/${ifpsHash}`;
102-
console.log(avatar);
103102

104-
console.log("user", user);
105103
const payload = {
106104
...user,
107105
avatarURI: avatar,
108106
};
109107

110-
console.log("payload", payload);
111-
112108
await editUser(user?.accountId!, payload);
113109
setUser(payload);
114110

src/components/dashboards/DashboardUsername.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const Username = ({ user }: { user: User }) => {
88
<Flex align="center" mt={2 || 0} ml={4}>
99
<Avatar
1010
size="md"
11-
name={user.username}
11+
name={user?.username}
1212
sx={{
1313
fontFamily: "Slackey",
1414
bgColor: "purple.500",
1515
}}
1616
/>
1717
<Flex direction="column" ml={2}>
1818
<Heading fontSize="lg" display="flex">
19-
{user.username}
19+
{user?.username}
2020
</Heading>
21-
<Text fontSize="md">{user.userType}</Text>
21+
<Text fontSize="md">{user?.userType}</Text>
2222
</Flex>
2323
</Flex>
2424
);

0 commit comments

Comments
 (0)