Skip to content

Commit

Permalink
Merge pull request #163 from Kevin-Umali/feature/TL-DYS-108
Browse files Browse the repository at this point in the history
[TL-DYS-108]
  • Loading branch information
Kevin-Umali authored Jun 22, 2024
2 parents 5e63dd5 + 77ee0d2 commit ee87c8f
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const useCheckBackEndHealthStatus = () => {
return useQuery({
queryKey: ["healthcheck"],
queryFn: () => checkBackEndHealthStatus(),
refetchOnWindowFocus: true,
});
};

Expand Down
34 changes: 31 additions & 3 deletions client/api/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,37 @@ import { ApiResponse, HealthCheckData, HttpMethod } from "@/interfaces";
import { fetchApi } from "@/lib/api-helper";

export const checkBackEndHealthStatus = (): Promise<ApiResponse<HealthCheckData>> => {
return fetchApi<ApiResponse<HealthCheckData>>("/v1/healthcheck", {
method: HttpMethod.GET,
});
return fetchApi<ApiResponse<HealthCheckData>>(
"/v1/healthcheck",
{
method: HttpMethod.GET,
timeout: 60000,
},
{
data: {
uptime: 0,
responseTime: [],
message: "Service unavailable",
timeStamp: Date.now(),
openaiStatus: {
name: "OpenAI",
status: "Outage",
message: "Service unavailable",
},
prismaStatus: {
name: "Prisma",
status: "Outage",
message: "Service unavailable",
},
apiStatus: {
name: "API",
status: "Outage",
message: "Service unavailable",
},
},
success: false,
},
);
};

export const subscribeToNewsletter = (email: string): Promise<any> => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/(account)/(routes)/diys/diys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Diys() {
</div>
</div>
<TabsContent value="all">
<Card x-chunk="dashboard-06-chunk-0">
<Card className="bg-transparent" x-chunk="dashboard-06-chunk-0">
<CardHeader>
<CardTitle>DIYS Project Ideas</CardTitle>
<CardDescription>Check out your DIYS projects</CardDescription>
Expand Down
41 changes: 41 additions & 0 deletions client/app/maintenance/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use client";

import type { Metadata } from "next";
import { useRouter } from "next/navigation";

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

export const metadata: Metadata = {
title: "Maintenance",
description: "Under Maintenance",
keywords: ["Maintenance", "Under Maintenance"],
metadataBase: new URL("https://www.diyspire.com/maintenance"),
applicationName: "DIYspire",
robots: {
index: false,
follow: false,
googleBot: {
index: false,
follow: false,
},
},
};

export default function Page() {
const { refresh } = useRouter();

return (
<div className="flex min-h-screen items-center justify-center py-5 sm:py-10">
<div className="p-6 text-center">
<Label className="mb-2 block text-2xl font-bold">Under Maintenance</Label>
<Label className="text-md my-4 block">You can try to refresh the page to see if the issue is resolved.</Label>
<div className="mt-4 flex flex-col space-y-2">
<Button onClick={refresh} className="w-full border px-4 py-2">
Refresh
</Button>
</div>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion client/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,4 @@ export const statusDown: ApiResponse<HealthCheckData> = {
},
};

export const accountRoutes: string[] = ["generate", "dashboard", "profile", "account", "project-detail", "diys"];
export const accountRoutes: string[] = ["generate", "dashboard", "profile", "account", "project-detail", "diys", "settings", "maintenance"];
2 changes: 1 addition & 1 deletion client/context/tanstackContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function TanstackQueryProvider({ children }: { children: React.Re
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: { queries: { retry: 2, refetchOnMount: false } },
defaultOptions: { queries: { retry: 2, refetchOnMount: false, refetchOnWindowFocus: false } },
}),
);
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
Expand Down
4 changes: 3 additions & 1 deletion client/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { AxiosRequestConfig } from "axios";

export interface FAQ {
id: string;
question: string;
Expand Down Expand Up @@ -250,7 +252,7 @@ export enum HttpMethod {
DELETE = "DELETE",
}

export type FetchApiOptions = {
export type FetchApiOptions = AxiosRequestConfig & {
method?: HttpMethod;
body?: object;
queryParams?: Record<string, string | number | boolean | string[] | number[] | undefined>;
Expand Down
10 changes: 8 additions & 2 deletions client/lib/api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ api.interceptors.response.use(
},
);

export const fetchApi = async <T>(endpoint: string, options: FetchApiOptions = {}): Promise<T> => {
export const fetchApi = async <T>(endpoint: string, options: FetchApiOptions = {}, defaultResponse?: T): Promise<T> => {
const { method = HttpMethod.GET, body, queryParams, accessToken } = options;

if (method === HttpMethod.GET && body) {
Expand All @@ -84,11 +84,17 @@ export const fetchApi = async <T>(endpoint: string, options: FetchApiOptions = {
paramsSerializer: (params) => serializeParams(params),
data: body,
headers: headers,
...options,
});

return response.data;
} catch (error: any) {
console.error("API Error: ", error.message);
throw error;

if (defaultResponse !== undefined) {
return defaultResponse;
} else {
throw error;
}
}
};
17 changes: 17 additions & 0 deletions client/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ const nextConfig = {
images: {
domains: ["images.unsplash.com", "via.placeholder.com"],
},
redirects: async () => {
return process.env.NEXT_PUBLIC_SHOW_MAINTENANCE === "true"
? [
{
source: "/((?!maintenance).*)",
destination: "/maintenance",
permanent: false,
},
]
: [
{
source: "/maintenance",
destination: "/",
permanent: false,
},
];
},
};

module.exports = nextConfig;

0 comments on commit ee87c8f

Please sign in to comment.