Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Dec 26, 2024
1 parent a36698c commit 132b3b9
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 142 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ jobs:
- run: pnpm install
- name: Build the application
env:
BACKEND_URL: "http://localhost:8080"
NEXT_PUBLIC_API_URL: "http://localhost:8080"
BACK_END_URL: "http://localhost:8080"
run: pnpm build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ Set up the application environment variables by running the following script:
scripts/init_environments.sh
```

This script generates environment variables, including BACKEND_URL, to establish the communication between the client and server. Example
This script generates environment variables, including NEXT_PUBLIC_API_URL, to establish the communication between the client and server. Example

```
BACKEND_URL=http://localhost:8080
NEXT_PUBLIC_API_URL=http://localhost:8080
```

We recommend running the `scripts/all.sh` script, as it streamlines the process by checking your environment settings and performing all necessary configurations, removing the need to execute multiple scripts manually.
Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const nextConfig = {
fallback: [
{
source: "/api/:path*",
destination: `${process.env.BACKEND_URL}/api/:path*`,
destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`,
},
],
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"nanoid": "^5.0.9",
"next": "^15.1.2",
"next-auth": "5.0.0-beta.25",
"next-runtime-env": "^3.2.2",
"next-themes": "^0.4.4",
"nuqs": "^2.2.3",
"react": "^19.0.0",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions scripts/docker_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ docker tag ${IMAGE_NAME} ${REMOTE_REPO}:${TAG}
docker tag ${IMAGE_NAME} ${REMOTE_REPO}:latest

# Step 3: Log in to the Docker repository (Docker Hub by default)
echo "Logging into Docker repository..."
docker login || { echo "Login failed"; exit 1; }

# Step 4: Push both tags to the remote repository
echo "Pushing Docker image to remote repository with tag '${TAG}'..."
docker push ${REMOTE_REPO}:${TAG}

echo "Pushing Docker image to remote repository with tag 'latest'..."
docker push ${REMOTE_REPO}:latest

echo "Docker image has been pushed successfully with tags '${TAG}' and 'latest'."
#echo "Logging into Docker repository..."
#docker login || { echo "Login failed"; exit 1; }
#
## Step 4: Push both tags to the remote repository
#echo "Pushing Docker image to remote repository with tag '${TAG}'..."
#docker push ${REMOTE_REPO}:${TAG}
#
#echo "Pushing Docker image to remote repository with tag 'latest'..."
#docker push ${REMOTE_REPO}:latest
#
#echo "Docker image has been pushed successfully with tags '${TAG}' and 'latest'."
3 changes: 2 additions & 1 deletion scripts/init_environments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ while true; do
done

# Append to the .env.local file
echo "BACKEND_URL=\"$backend_server\"" >> "$output_file"
echo "NEXT_PUBLIC_API_URL=\"$backend_server\"" >> "$output_file"
echo "BACK_END_URL=\"$backend_server\"" >> "$output_file"


# Run npx auth and append its output to .env
Expand Down
4 changes: 3 additions & 1 deletion src/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import LoginForm from "@/components/auth/login-form";
import { BACK_END_URL } from "@/lib/constants";

const LoginPage = () => {
const LoginPage = async () => {
console.log(`BACK_END ${BACK_END_URL}`);
return <LoginForm />;
};
export default LoginPage;
32 changes: 4 additions & 28 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import "./theme.css";

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { PublicEnvScript } from "next-runtime-env";

import AutoInitBackendApi from "@/components/init-api-backend";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import { setBackendUrl, setBaseUrl } from "@/lib/runtime-variables";
import { ErrorProvider } from "@/providers/error-provider";
import ReactQueryProvider from "@/providers/react-query-provider";
import { ThemeProvider } from "@/providers/theme-provider";
Expand All @@ -19,44 +18,21 @@ export const metadata: Metadata = {
description: "FlowInquiry dashboard",
};

const RootLayout = async ({
children,
}: Readonly<{
children: React.ReactNode;
}>) => {
const backendUrl = process.env.BACKEND_URL;
if (!backendUrl) {
throw new Error("BACKEND_URL is not defined in the environment");
}
setBackendUrl(backendUrl);

// Base url is the mandatory field in environments except local
const baseUrl = process.env.BASE_URL;
setBaseUrl(baseUrl);

const RootLayout = async ({ children }: { children: React.ReactNode }) => {
return (
<html suppressHydrationWarning={true} lang="en">
<head>
<PublicEnvScript />
<title>FlowInquiry - Ticket Management</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
{/* Favicon for modern browsers */}
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
{/* Fallback favicon for older browsers */}
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.png" />
</head>
<body className={inter.className}>
<script
id="runtime-config"
dangerouslySetInnerHTML={{
__html: `window.BASE_URL="${baseUrl}";`,
}}
/>
<ErrorProvider>
<ThemeProvider attribute="class" defaultTheme="system">
<ReactQueryProvider>
<TooltipProvider>
<AutoInitBackendApi /> {children}
</TooltipProvider>
<TooltipProvider>{children}</TooltipProvider>
<Toaster />
</ReactQueryProvider>
</ThemeProvider>
Expand Down
16 changes: 5 additions & 11 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { redirect } from "next/navigation";
import { Home } from "@/components/home";

import { auth } from "@/auth";
const Page = async () => {
return <Home />;
};

export default async function Home() {
const session = await auth();
if (!session) {
console.warn("No authentication. Redirect to the login page ...");
redirect("/login");
} else {
redirect("/portal");
}
}
export default Page;
3 changes: 1 addition & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export const { handlers, auth } = NextAuth({
if (!credentials) {
throw new Error("Invalid credentials");
}
const user = await apiAuthSignIn(credentials);
return user;
return await apiAuthSignIn(credentials);
},
}),
],
Expand Down
2 changes: 2 additions & 0 deletions src/components/admin-panel/content-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { Navbar } from "@/components/admin-panel/navbar";

interface ContentLayoutProps {
Expand Down
8 changes: 3 additions & 5 deletions src/components/admin-panel/user-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { getApiUrl, getBaseUrl } from "@/lib/runtime-variables";
import { API_URL } from "@/lib/constants";

export function UserNav() {
const { data: session } = useSession();
Expand All @@ -50,7 +50,7 @@ export function UserNav() {
<AvatarImage
src={
session?.user?.imageUrl
? `${getApiUrl()}/api/files/${session?.user?.imageUrl}`
? `${API_URL}/api/files/${session?.user?.imageUrl}`
: undefined
}
alt="Avatar"
Expand Down Expand Up @@ -102,7 +102,7 @@ export function UserNav() {
<DropdownMenuSeparator />
<DropdownMenuItem
className="hover:cursor-pointer"
onClick={() => signOut({ redirectTo: getBaseUrl() })}
onClick={() => signOut()}
>
<LogOut className="w-4 h-4 mr-3 text-muted-foreground" />
Sign out
Expand All @@ -111,12 +111,10 @@ export function UserNav() {
</DropdownMenu>
<DialogContent>
<DialogHeader className="flex items-center space-x-4">
{/* Logo */}
<div>
<AppLogo />
</div>

{/* Title and Description */}
<div>
<DialogTitle className="text-2xl font-bold">
FlowInquiry
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 @@ -40,7 +40,7 @@ import {
findUserById,
updateUser,
} from "@/lib/actions/users.action";
import { getApiUrl } from "@/lib/runtime-variables";
import { API_URL } from "@/lib/constants";
import { useError } from "@/providers/error-provider";
import { UserDTOSchema } from "@/types/users";

Expand Down Expand Up @@ -159,7 +159,7 @@ export const ProfileForm = () => {
<AvatarImage
src={
session?.user?.imageUrl
? `${getApiUrl()}/api/files/${session?.user?.imageUrl}`
? `${API_URL}/api/files/${session?.user?.imageUrl}`
: ""
}
alt="@flowinquiry"
Expand Down
13 changes: 13 additions & 0 deletions src/components/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use client";

import { redirect } from "next/navigation";
import { getSession } from "next-auth/react";

export const Home = async () => {
const session = getSession();
if (!session) {
redirect("/login");
} else {
redirect("/portal");
}
};
15 changes: 0 additions & 15 deletions src/components/init-api-backend.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/shared/avatar-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from "react";
import DefaultTeamLogo from "@/components/teams/team-logo";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import DefaultUserLogo from "@/components/users/user-logo";
import { getApiUrl } from "@/lib/runtime-variables";
import { API_URL } from "@/lib/constants";

interface AvatarDisplayProps {
imageUrl?: string | null;
Expand All @@ -25,7 +25,7 @@ export const AvatarDisplay: React.FC<AvatarDisplayProps> = ({
return (
<Avatar className={`${size} cursor-pointer ${className}`} onClick={onClick}>
<AvatarImage
src={imageUrl ? `${getApiUrl()}/api/files/${imageUrl}` : undefined}
src={imageUrl ? `${API_URL}/api/files/${imageUrl}` : undefined}
/>
<AvatarFallback>{fallbackContent}</AvatarFallback>
</Avatar>
Expand Down
4 changes: 2 additions & 2 deletions src/components/teams/team-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
findTeamById,
updateTeam,
} from "@/lib/actions/teams.action";
import { API_URL } from "@/lib/constants";
import { obfuscate } from "@/lib/endecode";
import { getApiUrl } from "@/lib/runtime-variables";
import { validateForm } from "@/lib/validator";
import { useError } from "@/providers/error-provider";
import { TeamDTO, TeamDTOSchema } from "@/types/teams";
Expand Down Expand Up @@ -175,7 +175,7 @@ export const TeamForm = ({ teamId }: { teamId: number | undefined }) => {
<AvatarImage
src={
team?.logoUrl
? `${getApiUrl()}/api/files/${team.logoUrl}`
? `${API_URL}/api/files/${team.logoUrl}`
: undefined
}
alt="@flowinquiry"
Expand Down
4 changes: 2 additions & 2 deletions src/components/teams/team-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {
import { useDebouncedCallback } from "@/hooks/use-debounced-callback";
import { usePagePermission } from "@/hooks/use-page-permission";
import { deleteTeams, searchTeams } from "@/lib/actions/teams.action";
import { API_URL } from "@/lib/constants";
import { obfuscate } from "@/lib/endecode";
import { getApiUrl } from "@/lib/runtime-variables";
import { cn } from "@/lib/utils";
import { useError } from "@/providers/error-provider";
import { Filter, QueryDTO } from "@/types/query";
Expand Down Expand Up @@ -206,7 +206,7 @@ export const TeamList = () => {
<AvatarImage
src={
team.logoUrl
? `${getApiUrl()}/api/files/${team.logoUrl}`
? `${API_URL}/api/files/${team.logoUrl}`
: undefined
}
alt="@flowinquiry"
Expand Down
4 changes: 2 additions & 2 deletions src/components/teams/team-users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {
deleteUserFromTeam,
findMembersByTeamId,
} from "@/lib/actions/teams.action";
import { API_URL } from "@/lib/constants";
import { obfuscate } from "@/lib/endecode";
import { getApiUrl } from "@/lib/runtime-variables";
import { BreadcrumbProvider } from "@/providers/breadcrumb-provider";
import { useError } from "@/providers/error-provider";
import { useTeam } from "@/providers/team-provider";
Expand Down Expand Up @@ -170,7 +170,7 @@ const TeamUsersView = () => {
<AvatarImage
src={
user?.imageUrl
? `${getApiUrl()}/api/files/${user.imageUrl}`
? `${API_URL}/api/files/${user.imageUrl}`
: undefined
}
alt={`${user.firstName} ${user.lastName}`}
Expand Down
7 changes: 0 additions & 7 deletions src/global.d.ts

This file was deleted.

Loading

0 comments on commit 132b3b9

Please sign in to comment.