Skip to content

Commit 587804d

Browse files
committed
[Dashboard] Remove chakra useToast (#4802)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on replacing the usage of `useToast` from `@chakra-ui/react` with `toast` from `sonner` for displaying notifications across various components in the dashboard. This change aims to streamline the notification handling. ### Detailed summary - Removed `useToast` from multiple components. - Replaced toast notifications with `toast.info`, `toast.success`, and `toast.error` methods from `sonner`. - Updated the `AddressCopyButton`, `PermissionsTable`, `LatestEvents`, `IpfsUploadDropzone`, and `AuthorizedWalletsTable` components to reflect these changes. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 3f83a37 commit 587804d

File tree

8 files changed

+23
-75
lines changed

8 files changed

+23
-75
lines changed

apps/dashboard/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ module.exports = {
5858
"VStack",
5959
"HStack",
6060
"AspectRatio",
61+
"useToast",
62+
"useClipboard",
6163
// also the types
6264
"ButtonProps",
6365
"BadgeProps",

apps/dashboard/src/components/ipfs-upload/dropzone.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
SimpleGrid,
1717
Tooltip,
1818
chakra,
19-
useToast,
2019
} from "@chakra-ui/react";
2120
import { useQueryClient } from "@tanstack/react-query";
2221
import { PINNED_FILES_QUERY_KEY_ROOT } from "components/storage/your-files";
@@ -27,6 +26,7 @@ import { type Dispatch, type SetStateAction, useMemo, useState } from "react";
2726
import { useDropzone } from "react-dropzone";
2827
import { BsFillCloudUploadFill } from "react-icons/bs";
2928
import { FiExternalLink, FiTrash2, FiUploadCloud } from "react-icons/fi";
29+
import { toast } from "sonner";
3030
import { MediaRenderer } from "thirdweb/react";
3131
import { useActiveAccount } from "thirdweb/react";
3232
import {
@@ -45,7 +45,6 @@ const TRACKING_CATEGORY = "ipfs_uploader";
4545
const UNACCEPTED_FILE_TYPES = ["text/html"];
4646

4747
export const IpfsUploadDropzone: React.FC = () => {
48-
const toast = useToast();
4948
const address = useActiveAccount()?.address;
5049

5150
const [droppedFiles, setDroppedFiles] = useState<File[]>([]);
@@ -56,13 +55,8 @@ export const IpfsUploadDropzone: React.FC = () => {
5655
UNACCEPTED_FILE_TYPES.includes(f.type),
5756
);
5857
if (invalidFiles.length) {
59-
const description = `${invalidFiles.length} ${invalidFiles.length > 1 ? "files have" : "file has"} been removed from the list. Uploading ${UNACCEPTED_FILE_TYPES.join(", ")} files is restricted.`;
60-
toast({
61-
title: "Error",
62-
description,
63-
status: "error",
64-
isClosable: true,
65-
duration: 6000,
58+
toast.error("Error", {
59+
description: `${invalidFiles.length} ${invalidFiles.length > 1 ? "files have" : "file has"} been removed from the list. Uploading ${UNACCEPTED_FILE_TYPES.join(", ")} files is restricted.`,
6660
});
6761
}
6862
setDroppedFiles((prev) => [

apps/dashboard/src/components/settings/AuthorizedWallets/AuthorizedWalletsTable.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import {
22
type AuthorizedWallet,
33
useRevokeAuthorizedWallet,
44
} from "@3rdweb-sdk/react/hooks/useApi";
5-
import { useDisclosure, useToast } from "@chakra-ui/react";
5+
import { useDisclosure } from "@chakra-ui/react";
66
import { createColumnHelper } from "@tanstack/react-table";
77
import { TWTable } from "components/shared/TWTable";
88
import { format } from "date-fns/format";
99
import { useTrack } from "hooks/analytics/useTrack";
1010
import { useState } from "react";
11+
import { toast } from "sonner";
1112
import { isAddress } from "thirdweb/utils";
1213
import { Button, Text } from "tw-components";
1314
import type { ComponentWithChildren } from "types/component-with-children";
@@ -25,7 +26,6 @@ const columnHelper = createColumnHelper<AuthorizedWallet>();
2526
export const AuthorizedWalletsTable: ComponentWithChildren<
2627
AuthorizedWalletsTableProps
2728
> = ({ authorizedWallets, isPending, isFetched }) => {
28-
const toast = useToast();
2929
const trackEvent = useTrack();
3030
const { mutateAsync: revokeAccess } = useRevokeAuthorizedWallet();
3131
const [revokeAuthorizedWalletId, setRevokeAuthorizedWalletId] = useState<
@@ -110,13 +110,7 @@ export const AuthorizedWalletsTable: ComponentWithChildren<
110110
action: "revoke-access-to-device",
111111
label: "success",
112112
});
113-
toast({
114-
title: "Device revoked",
115-
description: "The selected device has been revoked.",
116-
status: "success",
117-
duration: 5000,
118-
isClosable: true,
119-
});
113+
toast.success("The selected device has been revoked.");
120114
} catch (error) {
121115
console.error(error);
122116
trackEvent({
@@ -125,13 +119,9 @@ export const AuthorizedWalletsTable: ComponentWithChildren<
125119
label: "error",
126120
error,
127121
});
128-
toast({
129-
title: "Something went wrong while revoking the device",
122+
toast.error("Something went wrong while revoking the device", {
130123
description:
131-
"Something went wrong while revoking the device. Please visit our support site: https://thirdweb.com/support",
132-
status: "error",
133-
duration: 5000,
134-
isClosable: true,
124+
"Please visit our support site: https://thirdweb.com/support",
135125
});
136126
} finally {
137127
handleClose();

apps/dashboard/src/contract-ui/tabs/events/components/events-feed.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
Stack,
2323
Switch,
2424
Tooltip,
25-
useToast,
2625
} from "@chakra-ui/react";
2726
import { AiOutlineQuestionCircle } from "@react-icons/all-files/ai/AiOutlineQuestionCircle";
2827
import { AnimatePresence, motion } from "framer-motion";
@@ -31,6 +30,7 @@ import { useSearchParams } from "next/navigation";
3130
import { useRouter } from "next/router";
3231
import { Fragment, useMemo, useState } from "react";
3332
import { FiChevronDown, FiCopy } from "react-icons/fi";
33+
import { toast } from "sonner";
3434
import type { ThirdwebContract } from "thirdweb";
3535
import { stringify } from "thirdweb/utils";
3636
import {
@@ -191,7 +191,6 @@ const EventsFeedItem: React.FC<EventsFeedItemProps> = ({
191191
contractAddress,
192192
chainSlug,
193193
}) => {
194-
const toast = useToast();
195194
const { onCopy } = useClipboard(transaction.transactionHash);
196195

197196
const router = useRouter();
@@ -257,14 +256,7 @@ const EventsFeedItem: React.FC<EventsFeedItemProps> = ({
257256
bg="transparent"
258257
onClick={() => {
259258
onCopy();
260-
toast({
261-
variant: "solid",
262-
position: "bottom",
263-
title: "Transaction hash copied.",
264-
status: "success",
265-
duration: 5000,
266-
isClosable: true,
267-
});
259+
toast.info("Transaction hash copied.");
268260
}}
269261
>
270262
<Icon as={FiCopy} boxSize={3} />

apps/dashboard/src/contract-ui/tabs/overview/components/LatestEvents.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {
1212
Spinner,
1313
Stack,
1414
Tooltip,
15-
useToast,
1615
} from "@chakra-ui/react";
1716
import { useTabHref } from "contract-ui/utils";
1817
import { AnimatePresence, motion } from "framer-motion";
1918
import { useClipboard } from "hooks/useClipboard";
2019
import { useState } from "react";
2120
import { FiCopy } from "react-icons/fi";
21+
import { toast } from "sonner";
2222
import type { ThirdwebContract } from "thirdweb";
2323
import {
2424
Button,
@@ -109,7 +109,6 @@ interface EventsFeedItemProps {
109109
}
110110

111111
const EventsFeedItem: React.FC<EventsFeedItemProps> = ({ transaction }) => {
112-
const toast = useToast();
113112
const { onCopy } = useClipboard(transaction.transactionHash);
114113

115114
const href = useTabHref("events");
@@ -170,14 +169,7 @@ const EventsFeedItem: React.FC<EventsFeedItemProps> = ({ transaction }) => {
170169
bg="transparent"
171170
onClick={() => {
172171
onCopy();
173-
toast({
174-
variant: "solid",
175-
position: "bottom",
176-
title: "Transaction hash copied.",
177-
status: "success",
178-
duration: 5000,
179-
isClosable: true,
180-
});
172+
toast.info("Transaction hash copied.");
181173
}}
182174
>
183175
<Icon as={FiCopy} boxSize={3} />

apps/dashboard/src/contract-ui/tabs/overview/components/PermissionsTable.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import {
77
Stack,
88
Tag,
99
Tooltip,
10-
useToast,
1110
} from "@chakra-ui/react";
1211
import { useTabHref } from "contract-ui/utils";
1312
import { AnimatePresence, motion } from "framer-motion";
1413
import { useClipboard } from "hooks/useClipboard";
1514
import { useMemo } from "react";
1615
import { FiCopy } from "react-icons/fi";
16+
import { toast } from "sonner";
1717
import { type ThirdwebContract, ZERO_ADDRESS } from "thirdweb";
1818
import { useReadContract } from "thirdweb/react";
1919
import {
@@ -126,7 +126,6 @@ interface PermissionsItemProps {
126126
}
127127

128128
const PermissionsItem: React.FC<PermissionsItemProps> = ({ data }) => {
129-
const toast = useToast();
130129
const { onCopy } = useClipboard(data.member);
131130

132131
return (
@@ -183,14 +182,7 @@ const PermissionsItem: React.FC<PermissionsItemProps> = ({ data }) => {
183182
bg="transparent"
184183
onClick={() => {
185184
onCopy();
186-
toast({
187-
variant: "solid",
188-
position: "bottom",
189-
title: "Address copied.",
190-
status: "success",
191-
duration: 5000,
192-
isClosable: true,
193-
});
185+
toast.info("Address copied.");
194186
}}
195187
>
196188
<Icon as={FiCopy} boxSize={3} />

apps/dashboard/src/contract-ui/tabs/permissions/components/permissions-editor.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import {
1313
InputRightAddon,
1414
Stack,
1515
Tooltip,
16-
useToast,
1716
} from "@chakra-ui/react";
1817
import { DelayedDisplay } from "components/delayed-display/delayed-display";
1918
import { useClipboard } from "hooks/useClipboard";
2019
import { useState } from "react";
2120
import { useFieldArray, useFormContext } from "react-hook-form";
2221
import { BiPaste } from "react-icons/bi";
2322
import { FiCopy, FiInfo, FiPlus, FiTrash } from "react-icons/fi";
23+
import { toast } from "sonner";
2424
import { type ThirdwebContract, ZERO_ADDRESS, isAddress } from "thirdweb";
2525
import { Button, FormErrorMessage, Text } from "tw-components";
2626

@@ -172,8 +172,6 @@ const PermissionAddress: React.FC<PermissionAddressProps> = ({
172172
isSubmitting,
173173
contract,
174174
}) => {
175-
const toast = useToast();
176-
177175
const { onCopy } = useClipboard(member);
178176

179177
return (
@@ -193,14 +191,7 @@ const PermissionAddress: React.FC<PermissionAddressProps> = ({
193191
e.stopPropagation();
194192
e.preventDefault();
195193
onCopy();
196-
toast({
197-
position: "bottom",
198-
variant: "solid",
199-
title: "Address copied.",
200-
status: "success",
201-
duration: 5000,
202-
isClosable: true,
203-
});
194+
toast.info("Address copied.");
204195
}}
205196
/>
206197
</Tooltip>

apps/dashboard/src/tw-components/AddressCopyButton.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Icon, Tooltip, useToast } from "@chakra-ui/react";
1+
import { Icon, Tooltip } from "@chakra-ui/react";
22
import { useTrack } from "hooks/analytics/useTrack";
33
import { useClipboard } from "hooks/useClipboard";
44
import { FiCopy } from "react-icons/fi";
5+
import { toast } from "sonner";
56
import {
67
Button,
78
type ButtonProps,
@@ -47,7 +48,6 @@ export const AddressCopyButton: React.FC<AddressCopyButtonProps> = ({
4748
const { onCopy } = useClipboard(address || "");
4849

4950
const trackEvent = useTrack();
50-
const toast = useToast();
5151

5252
return (
5353
<Tooltip
@@ -70,14 +70,9 @@ export const AddressCopyButton: React.FC<AddressCopyButtonProps> = ({
7070
e.stopPropagation();
7171
e.preventDefault();
7272
onCopy();
73-
toast({
74-
variant: "solid",
75-
position: "bottom",
76-
title: `${title.charAt(0).toUpperCase() + title.slice(1)} copied.`,
77-
status: "success",
78-
duration: 5000,
79-
isClosable: true,
80-
});
73+
toast.info(
74+
`${title.charAt(0).toUpperCase() + title.slice(1)} copied.`,
75+
);
8176
if (title === "Token ID") {
8277
trackEvent({
8378
category: "tokenid_button",

0 commit comments

Comments
 (0)