Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to nextjs15 and react19 #33

Merged
merged 5 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update
  • Loading branch information
haiphucnguyen committed Dec 13, 2024
commit c4f638ef0050b5753e000a3c77015e4fa1b53142
6 changes: 4 additions & 2 deletions src/app/account/reset/finish/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ function ActivationContent() {
);
}

export default function Page() {
const Page = () => {
return (
<Suspense fallback={<p>Loading...</p>}>
<ActivationContent />
</Suspense>
);
}
};

export default Page;
8 changes: 5 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export const metadata: Metadata = {
description: "Flexwork dashboard",
};

export default async function RootLayout({
const RootLayout = async ({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
}>) => {
return (
<html suppressHydrationWarning={true} lang="en">
<head>
Expand All @@ -40,4 +40,6 @@ export default async function RootLayout({
</body>
</html>
);
}
};

export default RootLayout;
6 changes: 4 additions & 2 deletions src/app/portal/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import UserNotifications from "@/components/dashboard/notifications-user";
import TeamUnresolvedTicketsPriorityDistributionChart from "@/components/dashboard/team-unresolved-tickets-priority-distribution";
import UserTeamsOverdueTickets from "@/components/dashboard/user-requests-overdue";

export default function Home() {
const Page = () => {
return (
<ContentLayout title="Dashboard">
<h1 className="text-2xl mb-4">Dashboard</h1>
Expand All @@ -27,4 +27,6 @@ export default function Home() {
</div>
</ContentLayout>
);
}
};

export default Page;
8 changes: 5 additions & 3 deletions src/app/portal/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useEffect } from "react";

import { Button } from "@/components/ui/button";

export default function Error({
const Error = ({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
}) => {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
Expand All @@ -29,4 +29,6 @@ export default function Error({
</Button>
</div>
);
}
};

export default Error;
4 changes: 2 additions & 2 deletions src/app/portal/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { auth } from "@/auth";
import AdminPanelLayout from "@/components/admin-panel/admin-panel-layout";
import { PermissionsProvider } from "@/providers/permissions-provider";

const MainLayout = async ({ children }: { children: React.ReactNode }) => {
const Layout = async ({ children }: { children: React.ReactNode }) => {
const session = await auth();
if (!session) {
console.log("No session is detected. Redirect to login page");
Expand All @@ -21,4 +21,4 @@ const MainLayout = async ({ children }: { children: React.ReactNode }) => {
);
};

export default MainLayout;
export default Layout;
7 changes: 5 additions & 2 deletions src/app/portal/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import React from "react";

import { Button } from "@/components/ui/button";

export default function NotFound() {
const NotFound = () => {
const router = useRouter();

return (
<main className="flex h-full flex-col items-center justify-center gap-2">
<FrownIcon className="w-10 text-gray-400" />
Expand All @@ -21,4 +22,6 @@ export default function NotFound() {
</Button>
</main>
);
}
};

export default NotFound;
8 changes: 4 additions & 4 deletions src/app/portal/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from "next/navigation";

export default function Home() {
// Load the user authority permission

const Page = () => {
redirect("/portal/dashboard");
}
};

export default Page;
4 changes: 2 additions & 2 deletions src/app/portal/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const breadcrumbItems = [
{ title: "Profile", link: "/portal/profile" },
];

const ProfilePage = () => {
const Page = () => {
return (
<SimpleContentView title="Profile" breadcrumbItems={breadcrumbItems}>
<ProfileForm />
</SimpleContentView>
);
};

export default ProfilePage;
export default Page;
10 changes: 4 additions & 6 deletions src/app/portal/settings/authorities/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import React from "react";

import { ResourceProvider } from "@/providers/resource-provider";

export default function TeamsLayout({
children,
}: {
children: React.ReactNode;
}) {
const Layout = ({ children }: { children: React.ReactNode }) => {
return (
<ResourceProvider resourceId="Authorities">
<div>{children}</div>
</ResourceProvider>
);
}
};

export default Layout;
10 changes: 4 additions & 6 deletions src/app/portal/settings/workflows/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import React from "react";

import { ResourceProvider } from "@/providers/resource-provider";

export default function WorkflowsLayout({
children,
}: {
children: React.ReactNode;
}) {
const Layout = ({ children }: { children: React.ReactNode }) => {
return (
<ResourceProvider resourceId="Workflows">
<div>{children}</div>
</ResourceProvider>
);
}
};

export default Layout;
8 changes: 4 additions & 4 deletions src/app/portal/teams/[teamId]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { SimpleContentView } from "@/components/admin-panel/simple-content-view"
import { TeamForm } from "@/components/teams/team-form";
import { deobfuscateToNumber } from "@/lib/endecode";

export default async function Page(props: {
params: Promise<{ teamId: string | "new" }>;
}) {
const Page = async (props: { params: Promise<{ teamId: string | "new" }> }) => {
const params = await props.params;
const teamId =
params.teamId !== "new" ? deobfuscateToNumber(params.teamId) : undefined;
Expand All @@ -14,4 +12,6 @@ export default async function Page(props: {
<TeamForm teamId={teamId} />
</SimpleContentView>
);
}
};

export default Page;
19 changes: 12 additions & 7 deletions src/app/portal/teams/[teamId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import { deobfuscateToNumber } from "@/lib/endecode";
import { TeamProvider } from "@/providers/team-provider";
import { UserTeamRoleProvider } from "@/providers/user-team-role-provider";

export default async function TeamsLayout(props: {
const Layout = async ({
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ teamId: string }>;
}) {
const params = await props.params;

const { children } = props;
}) => {
const resolvedParams = await params;

const teamIdNum =
params.teamId === "new" ? null : deobfuscateToNumber(params.teamId);
resolvedParams.teamId === "new"
? null
: deobfuscateToNumber(resolvedParams.teamId);

if (teamIdNum == null) {
return children;
Expand All @@ -27,4 +30,6 @@ export default async function TeamsLayout(props: {
<UserTeamRoleProvider teamId={teamIdNum}>{children}</UserTeamRoleProvider>
</TeamProvider>
);
}
};

export default Layout;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import TeamNavLayout from "@/components/teams/team-nav";
import { TeamRequestForm } from "@/components/teams/team-requests-form";
import { deobfuscateToNumber } from "@/lib/endecode";

export default async function Page(props: {
const Page = async (props: {
params: Promise<{ teamId: string; requestId: string }>;
}) {
}) => {
const params = await props.params;
const teamRequestId = deobfuscateToNumber(params.requestId);

Expand All @@ -18,4 +18,6 @@ export default async function Page(props: {
</TeamNavLayout>
</ContentLayout>
);
}
};

export default Page;
23 changes: 15 additions & 8 deletions src/app/portal/users/[userId]/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { SimpleContentView } from "@/components/admin-panel/simple-content-view";
import { UserForm } from "@/components/users/user-form";
import { deobfuscateToNumber } from "@/lib/endecode";

const breadcrumbItems = [
{ title: "Dashboard", link: "/portal" },
{ title: "Users", link: "/portal/users" },
{ title: "Create", link: "/portal/users/edit/new" },
];
const Page = async (props: { params: Promise<{ userId: string | "new" }> }) => {
const params = await props.params;
const userId =
params.userId !== "new" ? deobfuscateToNumber(params.userId) : undefined;

const breadcrumbItems = [
{ title: "Dashboard", link: "/portal" },
{ title: "Users", link: "/portal/users" },
{ title: "Create", link: "/portal/users/edit/new" },
];

export default function Page() {
return (
<SimpleContentView title="Users" breadcrumbItems={breadcrumbItems}>
<UserForm initialData={null} key={null} />
<UserForm userId={userId} />
</SimpleContentView>
);
}
};

export default Page;
10 changes: 4 additions & 6 deletions src/app/portal/users/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import React from "react";

import { ResourceProvider } from "@/providers/resource-provider";

export default function TeamsLayout({
children,
}: {
children: React.ReactNode;
}) {
const TeamsLayout = ({ children }: { children: React.ReactNode }) => {
return (
<ResourceProvider resourceId="Users">
<div>{children}</div>
</ResourceProvider>
);
}
};

export default TeamsLayout;
16 changes: 11 additions & 5 deletions src/components/authorities/authority-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { Spinner } from "@/components/ui/spinner";
import { Textarea } from "@/components/ui/textarea";
import {
batchSavePermissions,
createAuthority,
Expand All @@ -50,9 +50,13 @@ type FormData = z.infer<typeof formSchema>;

const permissionOptions = ["NONE", "READ", "WRITE", "ACCESS"];

const AuthorityForm = ({ authorityId }: { authorityId: string }) => {
const AuthorityForm = ({
authorityId,
}: {
authorityId: string | undefined;
}) => {
const router = useRouter();
const [loading, setLoading] = useState(true);
const [loading, setLoading] = useState(!!authorityId); // Only show loading if authorityId is present
const [error, setError] = useState<string | null>(null);
const [authorityResourcePermissions, setAuthorityResourcePermissions] =
useState<Array<AuthorityResourcePermissionDTO>>([]);
Expand All @@ -75,6 +79,8 @@ const AuthorityForm = ({ authorityId }: { authorityId: string }) => {

useEffect(() => {
async function fetchAuthorityAndPermissions() {
if (!authorityId) return; // Skip fetching if authorityId is undefined

try {
const fetchedAuthority = await findAuthorityByName(authorityId);

Expand Down Expand Up @@ -142,7 +148,7 @@ const AuthorityForm = ({ authorityId }: { authorityId: string }) => {
if (loading) {
return (
<div className="flex justify-center items-center h-full">
<Spinner /> {/* Display a spinner while loading */}
<Spinner>Loading data...</Spinner>
</div>
);
}
Expand Down Expand Up @@ -221,7 +227,7 @@ const AuthorityForm = ({ authorityId }: { authorityId: string }) => {
<FormControl>
<Select
onValueChange={field.onChange}
defaultValue={field.value || "NONE"}
value={field.value ?? "NONE"}
disabled={isSystemRole}
>
<SelectTrigger>
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/profile-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import { useImageCropper } from "@/hooks/use-image-cropper";
import { findUserById } from "@/lib/actions/users.action";
import { apiClient } from "@/lib/api-client";
import { obfuscate } from "@/lib/endecode";
import { userSchema } from "@/types/users";
import { UserTypeSchema } from "@/types/users";

const userSchemaWithFile = userSchema.extend({
const userSchemaWithFile = UserTypeSchema.extend({
file: z.any().optional(), // Add file as an optional field of any type
});

Expand Down
Loading
Loading