-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement HOC patern for admin components
- Loading branch information
1 parent
a30c551
commit df243b6
Showing
14 changed files
with
404 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use server"; | ||
import { revalidatePath } from "next/cache"; | ||
import { adminAction } from "@/lib/next-safe-action"; | ||
import adminService from "@/services/admin.service"; | ||
import * as z from "zod"; | ||
|
||
const schema = z.object({ | ||
userId: z.string(), | ||
}); | ||
|
||
export const updateUserRole = adminAction(schema, async (data) => { | ||
try { | ||
await adminService.updateUserRole(data.userId); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
|
||
revalidatePath("/repositories"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client"; | ||
import React, { useEffect, useState } from "react"; | ||
import io from "socket.io-client"; | ||
|
||
const API_URL = "https://nodejs-production-eb8a.up.railway.app/"; | ||
const socket = io(API_URL, { autoConnect: false }); | ||
|
||
export default function SocketIOPage() { | ||
const [views, setViews] = useState(0); | ||
|
||
useEffect(() => { | ||
socket.connect(); | ||
socket.on("count", (count: number) => { | ||
setViews(count); | ||
}); | ||
|
||
return () => { | ||
socket.disconnect(); | ||
}; | ||
}, []); | ||
|
||
return <div>{views}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { User } from "@/types/prisma.type"; | ||
|
||
export const withAdminRole = <P extends object>( | ||
Component: React.ComponentType<P>, | ||
) => { | ||
const WithAdminRole = ({ | ||
role, | ||
...props | ||
}: P & { role: User["role"] | undefined }) => { | ||
return role === "ADMIN" ? <Component {...(props as P)} /> : null; | ||
}; | ||
|
||
WithAdminRole.displayName = `WithAdminRole(${Component.displayName ?? Component.name ?? "Component"})`; | ||
|
||
return WithAdminRole; | ||
}; |
Oops, something went wrong.