Skip to content

Commit 6f0a6a3

Browse files
committed
feat: migrate to app router
1 parent 73af821 commit 6f0a6a3

File tree

47 files changed

+242
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+242
-179
lines changed
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
'use client';
2+
13
import BurnReport from '@components/account/BurnReport';
24
import Invoicing from '@components/account/invoicing/Invoicing';
35
import Profile from '@components/account/profile/Profile';
46
import { routePath } from '@lib/routes/route-paths';
57
import CustomTabs from '@shared/CustomTabs';
6-
import { useRouter } from 'next/router';
8+
import { useRouter, useSearchParams } from 'next/navigation';
79
import { useEffect, useState } from 'react';
810
import { CgProfile } from 'react-icons/cg';
911
import { RiBillLine, RiFireLine } from 'react-icons/ri';
1012

11-
function Account() {
13+
export default function Account() {
1214
const [selectedTab, setSelectedTab] = useState<'invoicing' | 'profile' | 'burn-report'>('invoicing');
1315
const router = useRouter();
16+
const searchParams = useSearchParams();
1417

1518
useEffect(() => {
16-
const { tab } = router.query;
19+
const tab = searchParams.get('tab');
1720
if (tab && (tab === 'invoicing' || tab === 'profile' || tab === 'burn-report')) {
1821
setSelectedTab(tab as 'invoicing' | 'profile' | 'burn-report');
1922
}
20-
}, [router.query]);
23+
}, [searchParams]);
2124

2225
return (
2326
<div className="col w-full flex-1 gap-5">
@@ -45,10 +48,7 @@ function Account() {
4548
]}
4649
selectedKey={selectedTab}
4750
onSelectionChange={(key) => {
48-
router.push({
49-
pathname: routePath.account,
50-
query: { tab: key },
51-
});
51+
router.push(`${routePath.account}?tab=${key}`);
5252
}}
5353
/>
5454

@@ -58,5 +58,3 @@ function Account() {
5858
</div>
5959
);
6060
}
61-
62-
export default Account;

pages/deeploys/create-project.tsx renamed to app/(protected)/deeploys/create-project/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
'use client';
2+
13
import ProjectForm from '@components/create-project/ProjectForm';
24
import { COLOR_TYPES } from '@data/colorTypes';
35
import { zodResolver } from '@hookform/resolvers/zod';
46
import { routePath } from '@lib/routes/route-paths';
57
import db from '@lib/storage/db';
68
import { projectSchema } from '@schemas/project';
79
import SupportFooter from '@shared/SupportFooter';
8-
import { useRouter } from 'next/router';
10+
import { useRouter } from 'next/navigation';
911
import { FormProvider, useForm } from 'react-hook-form';
1012
import toast from 'react-hot-toast';
1113
import { keccak256, toBytes } from 'viem';

pages/deeploys/dashboard.tsx renamed to app/(protected)/deeploys/dashboard/page.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
'use client';
2+
13
import Drafts from '@components/deeploys/Drafts';
24
import Running, { RunningRef } from '@components/deeploys/Running';
35
import { routePath } from '@lib/routes/route-paths';
46
import db from '@lib/storage/db';
57
import ActionButton from '@shared/ActionButton';
68
import CustomTabs from '@shared/CustomTabs';
79
import { useLiveQuery } from 'dexie-react-hooks';
8-
import { useRouter } from 'next/router';
10+
import { useRouter, useSearchParams } from 'next/navigation';
911
import { useEffect, useRef, useState } from 'react';
1012
import { RiBox2Line, RiFileTextLine } from 'react-icons/ri';
1113

12-
function Dashboard() {
14+
export default function Dashboard() {
1315
const [selectedTab, setSelectedTab] = useState<'running' | 'drafts'>('running');
1416
const drafts = useLiveQuery(() => db.projects.toArray());
1517
const runningRef = useRef<RunningRef>(null);
1618

1719
const [projectsCount, setProjectsCount] = useState(0);
1820

1921
const router = useRouter();
22+
const searchParams = useSearchParams();
2023

21-
// Used to display a message with the successfully deployed jobs right after deployment
2224
const [visibleSuccessfulJobs, setVisibleSuccessfulJobs] = useState<{ text: string; serverAlias: string }[]>([]);
2325

2426
useEffect(() => {
25-
if (!router.isReady) return;
2627
const stored = sessionStorage.getItem('successfulJobs');
2728
if (stored) {
2829
try {
@@ -36,14 +37,14 @@ function Dashboard() {
3637
sessionStorage.removeItem('successfulJobs');
3738
}
3839
}
39-
}, [router.isReady]);
40+
}, []);
4041

4142
useEffect(() => {
42-
const { tab } = router.query;
43+
const tab = searchParams.get('tab');
4344
if (tab && (tab === 'running' || tab === 'drafts')) {
4445
setSelectedTab(tab as 'running' | 'drafts');
4546
}
46-
}, [router.query]);
47+
}, [searchParams]);
4748

4849
const handleExpandAll = () => {
4950
runningRef.current?.expandAll();
@@ -77,10 +78,7 @@ function Dashboard() {
7778
]}
7879
selectedKey={selectedTab}
7980
onSelectionChange={(key) => {
80-
router.push({
81-
pathname: `${routePath.deeploys}/${routePath.dashboard}`,
82-
query: { tab: key },
83-
});
81+
router.push(`${routePath.deeploys}/${routePath.dashboard}?tab=${key}`);
8482
}}
8583
/>
8684

@@ -110,5 +108,3 @@ function Dashboard() {
110108
</div>
111109
);
112110
}
113-
114-
export default Dashboard;

pages/deeploys/job-draft/[draftId].tsx renamed to app/(protected)/deeploys/job-draft/[draftId]/page.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import DraftEditFormWrapper from '@components/draft/DraftEditFormWrapper';
24
import JobDraftBreadcrumbs from '@components/draft/JobDraftBreadcrumbs';
35
import { DeploymentContextType, useDeploymentContext } from '@lib/contexts/deployment';
@@ -7,7 +9,7 @@ import ActionButton from '@shared/ActionButton';
79
import SupportFooter from '@shared/SupportFooter';
810
import { DraftJob, JobType, NativeDraftJob, ServiceDraftJob } from '@typedefs/deeploys';
911
import { useLiveQuery } from 'dexie-react-hooks';
10-
import { useRouter } from 'next/router';
12+
import { useParams, useRouter } from 'next/navigation';
1113
import { useEffect } from 'react';
1214
import toast from 'react-hot-toast';
1315
import { RiArrowLeftLine } from 'react-icons/ri';
@@ -17,8 +19,8 @@ export default function EditJobDraft() {
1719
const { setStep } = useDeploymentContext() as DeploymentContextType;
1820

1921
const router = useRouter();
20-
const draftIdParam = router.query.draftId;
21-
const draftId = Array.isArray(draftIdParam) ? draftIdParam[0] : draftIdParam;
22+
const params = useParams<{ draftId?: string }>();
23+
const draftId = params?.draftId;
2224

2325
const draftJob: DraftJob | undefined | null = useLiveQuery(
2426
draftId ? () => db.jobs.get(parseInt(draftId)) : () => undefined,

pages/deeploys/job/[jobId]/edit.tsx renamed to app/(protected)/deeploys/job/[jobId]/edit/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { CspEscrowAbi } from '@blockchain/CspEscrow';
24
import { DeeployFlowModal } from '@components/draft/DeeployFlowModal';
35
import JobEditFormWrapper from '@components/edit-job/JobEditFormWrapper';
@@ -22,6 +24,7 @@ import { jobSchema } from '@schemas/index';
2224
import ActionButton from '@shared/ActionButton';
2325
import DeeployErrors from '@shared/jobs/DeeployErrors';
2426
import SupportFooter from '@shared/SupportFooter';
27+
import { useRunningJob } from '@lib/hooks/useRunningJob';
2528
import {
2629
GenericJobDeployment,
2730
GenericJobSpecifications,
@@ -33,11 +36,10 @@ import {
3336
ServiceJobSpecifications,
3437
} from '@typedefs/deeploys';
3538
import { JOB_TYPE_OPTIONS, JobTypeOption } from '@typedefs/jobType';
36-
import { useRunningJob } from '@lib/hooks/useRunningJob';
3739
import { useEffect, useRef, useState } from 'react';
3840
import { toast } from 'react-hot-toast';
3941
import { RiArrowLeftLine } from 'react-icons/ri';
40-
import { useRouter } from 'next/router';
42+
import { useParams, useRouter } from 'next/navigation';
4143
import { useAccount, usePublicClient, useSignMessage, useWalletClient } from 'wagmi';
4244
import z from 'zod';
4345

@@ -46,8 +48,8 @@ export default function EditJob() {
4648
const { setFetchAppsRequired, setStep, escrowContractAddress } = useDeploymentContext() as DeploymentContextType;
4749

4850
const router = useRouter();
49-
const jobIdParam = router.query.jobId;
50-
const jobId = Array.isArray(jobIdParam) ? jobIdParam[0] : jobIdParam;
51+
const params = useParams<{ jobId?: string }>();
52+
const jobId = params?.jobId;
5153
const { job, isLoading: isJobLoading } = useRunningJob(jobId, {
5254
onError: () => router.replace('/404'),
5355
});

pages/deeploys/job/[jobId]/extend.tsx renamed to app/(protected)/deeploys/job/[jobId]/extend/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
'use client';
2+
13
import JobExtension from '@components/extend-job/JobExtension';
24
import JobBreadcrumbs from '@components/job/JobBreadcrumbs';
35
import ExtendJobPageLoading from '@components/loading/ExtendJobPageLoading';
46
import ActionButton from '@shared/ActionButton';
57
import SupportFooter from '@shared/SupportFooter';
68
import { JOB_TYPE_OPTIONS, JobTypeOption } from '@typedefs/jobType';
79
import { useRunningJob } from '@lib/hooks/useRunningJob';
8-
import { useRouter } from 'next/router';
9-
import { useEffect, useMemo, useState } from 'react';
10+
import { useParams, useRouter } from 'next/navigation';
11+
import { useEffect, useState } from 'react';
1012
import { RiArrowLeftLine } from 'react-icons/ri';
1113

1214
export default function ExtendJob() {
1315
const router = useRouter();
14-
const jobIdParam = router.query.jobId;
15-
const jobId = useMemo(() => (Array.isArray(jobIdParam) ? jobIdParam[0] : jobIdParam), [jobIdParam]);
16+
const params = useParams<{ jobId?: string }>();
17+
const jobId = params?.jobId;
1618
const { job, isLoading } = useRunningJob(jobId, {
1719
onError: () => router.replace('/404'),
1820
});

pages/deeploys/job/[jobId]/index.tsx renamed to app/(protected)/deeploys/job/[jobId]/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import JobDeploymentSection from '@components/job/config/JobDeploymentSection';
24
import JobPluginsSection from '@components/job/config/JobPluginsSection';
35
import JobBreadcrumbs from '@components/job/JobBreadcrumbs';
@@ -16,15 +18,15 @@ import SupportFooter from '@shared/SupportFooter';
1618
import { JOB_TYPE_OPTIONS, JobTypeOption } from '@typedefs/jobType';
1719
import { uniq } from 'lodash';
1820
import Link from 'next/link';
19-
import { useRouter } from 'next/router';
20-
import { useEffect, useMemo, useState } from 'react';
21+
import { useParams, useRouter } from 'next/navigation';
22+
import { useEffect, useState } from 'react';
2123
import { RiArrowLeftLine, RiCloseFill } from 'react-icons/ri';
2224

2325
export default function Job() {
2426
const { fetchApps } = useDeploymentContext() as DeploymentContextType;
2527
const router = useRouter();
26-
const jobIdParam = router.query.jobId;
27-
const jobId = useMemo(() => (Array.isArray(jobIdParam) ? jobIdParam[0] : jobIdParam), [jobIdParam]);
28+
const params = useParams<{ jobId?: string }>();
29+
const jobId = params?.jobId;
2830

2931
const { job, isLoading, fetchJob } = useRunningJob(jobId, {
3032
onError: () => router.replace(routePath.notFound),

pages/deeploys/legacy-requester.tsx renamed to app/(protected)/deeploys/legacy-requester/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { Button } from '@heroui/button';
24
import { SelectItem } from '@heroui/select';
35
import { config, environment, getDevAddress, isUsingDevAddress } from '@lib/config';
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { CspEscrowAbi } from '@blockchain/CspEscrow';
24
import { getRunningJobResources, RunningJobResources } from '@data/containerResources';
35
import { Skeleton } from '@heroui/skeleton';
@@ -22,8 +24,8 @@ import { JOB_TYPE_OPTIONS, JobTypeOption } from '@typedefs/jobType';
2224
import { useLiveQuery } from 'dexie-react-hooks';
2325
import _ from 'lodash';
2426
import Link from 'next/link';
25-
import { useRouter } from 'next/router';
26-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
27+
import { useRouter } from 'next/navigation';
28+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
2729
import toast from 'react-hot-toast';
2830
import { RiCalendarLine, RiDraftLine, RiTimeLine } from 'react-icons/ri';
2931
import { usePublicClient, useWalletClient } from 'wagmi';
@@ -400,7 +402,7 @@ export default function Monitor() {
400402
);
401403
}
402404

403-
function Wrapper({ children }: { children: React.ReactNode }) {
405+
function Wrapper({ children }: { children: ReactNode }) {
404406
return (
405407
<div className="mx-auto w-3xl">
406408
<div className="list">{children}</div>

app/(protected)/deeploys/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { redirect } from 'next/navigation';
2+
3+
export default function DeeploysIndex() {
4+
redirect('/deeploys/dashboard');
5+
}

0 commit comments

Comments
 (0)