Skip to content

Commit 5aa8e8e

Browse files
committed
final changes
1 parent 9853e17 commit 5aa8e8e

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ export function LinkPageClient() {
5050
},
5151
{
5252
keepPreviousData: true,
53-
onError: (error) => {
53+
// doing onErrorRetry to avoid race condiition for when a link's domain / key is updated
54+
onErrorRetry: (error, _key, _config, revalidate, { retryCount }) => {
5455
if (error.status === 401 || error.status === 404) {
55-
router.push(`/${workspace.slug}/links`);
56+
if (retryCount >= 3) {
57+
router.push(`/${workspace.slug}/links`);
58+
return;
59+
}
5660
}
61+
// Default retry behavior for other errors
62+
setTimeout(() => revalidate({ retryCount }), 5000);
5763
},
5864
},
5965
);

apps/web/lib/swr/use-folder.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,27 @@ import useWorkspace from "./use-workspace";
55

66
export default function useFolder({
77
folderId,
8-
enabled: enabledOverride,
8+
enabled,
99
}: {
1010
folderId?: string | null;
1111
enabled?: boolean;
1212
}) {
1313
const { id: workspaceId, plan, flags } = useWorkspace();
1414

15-
const defaultEnabled =
15+
const swrEnabled =
16+
enabled &&
1617
folderId &&
1718
folderId !== "unsorted" &&
1819
workspaceId &&
1920
flags?.linkFolders &&
2021
plan !== "free";
2122

22-
const enabled =
23-
enabledOverride !== undefined ? enabledOverride : defaultEnabled;
24-
2523
const {
2624
data: folder,
2725
isValidating,
2826
isLoading,
2927
} = useSWR<Folder>(
30-
enabled ? `/api/folders/${folderId}?workspaceId=${workspaceId}` : null,
28+
swrEnabled ? `/api/folders/${folderId}?workspaceId=${workspaceId}` : null,
3129
fetcher,
3230
{
3331
dedupingInterval: 60000,

apps/web/ui/links/link-builder/use-link-builder-submit.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mutatePrefix } from "@/lib/swr/mutate";
22
import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";
3-
import { useCopyToClipboard, useRouterStuff } from "@dub/ui";
3+
import { useCopyToClipboard } from "@dub/ui";
4+
import { useRouter } from "next/navigation";
45
import posthog from "posthog-js";
56
import { useCallback } from "react";
67
import { useFormContext } from "react-hook-form";
@@ -13,7 +14,7 @@ export function useLinkBuilderSubmit({
1314
}: {
1415
onSuccess?: (data: LinkFormData) => void;
1516
} = {}) {
16-
const { queryParams } = useRouterStuff();
17+
const router = useRouter();
1718
const { workspace, props } = useLinkBuilderContext();
1819
const { getValues, setError } = useFormContext<LinkFormData>();
1920

@@ -61,6 +62,15 @@ export function useLinkBuilderSubmit({
6162
const data = await res.json();
6263
onSuccess?.(data);
6364

65+
// for editing links, if domain / key is changed, push to new url
66+
console.log({ props, data });
67+
if (
68+
props &&
69+
(props.domain !== data.domain || props.key !== data.key)
70+
) {
71+
router.push(`/${workspace.slug}/links/${data.domain}/${data.key}`);
72+
}
73+
6474
await mutatePrefix([
6575
"/api/links",
6676
// if updating root domain link, mutate domains as well

0 commit comments

Comments
 (0)