diff --git a/admin/package.json b/admin/package.json index 14483444..12509be1 100644 --- a/admin/package.json +++ b/admin/package.json @@ -12,6 +12,7 @@ "dependencies": { "class-variance-authority": "^0.7.0", "react": "^18.3.1", + "react-cookie": "^7.2.0", "react-dom": "^18.3.1", "react-router-dom": "^6.25.1" }, diff --git a/admin/public/assets/icons/calendar.svg b/admin/public/assets/icons/calendar.svg index 6d839977..bcd55ca9 100644 --- a/admin/public/assets/icons/calendar.svg +++ b/admin/public/assets/icons/calendar.svg @@ -1,8 +1,9 @@
- - - +
); diff --git a/admin/src/components/Route/index.tsx b/admin/src/components/Route/index.tsx new file mode 100644 index 00000000..3fc05ffb --- /dev/null +++ b/admin/src/components/Route/index.tsx @@ -0,0 +1,27 @@ +import { useCookies } from "react-cookie"; +import { Navigate, Outlet } from "react-router-dom"; +import { COOKIE_KEY } from "@/constants/cookie"; + +interface RouteProps { + redirectPath?: string; +} + +export function ProtectedRoute({ redirectPath = "/login" }: RouteProps) { + const [cookies] = useCookies([COOKIE_KEY.ACCESS_TOKEN]); + + if (!cookies[COOKIE_KEY.ACCESS_TOKEN]) { + return ; + } + + return ; +} + +export function UnProtectedRoute({ redirectPath = "/lottery" }: RouteProps) { + const [cookies] = useCookies([COOKIE_KEY.ACCESS_TOKEN]); + + if (cookies[COOKIE_KEY.ACCESS_TOKEN]) { + return ; + } + + return ; +} diff --git a/admin/src/components/SelectForm/index.tsx b/admin/src/components/SelectForm/index.tsx new file mode 100644 index 00000000..693d7b32 --- /dev/null +++ b/admin/src/components/SelectForm/index.tsx @@ -0,0 +1,38 @@ +import { ReactNode } from "react"; + +interface SelectFormProps { + header: ReactNode; + data: ReactNode[][]; +} + +export default function SelectForm({ header, data }: SelectFormProps) { + return ( +
+
+ + + + + + + + {data.map((tableData, idx) => ( + + {tableData.map((dataNode, idx) => ( + + ))} + + ))} + +
+ {header} +
+ {dataNode} +
+
+
+ ); +} diff --git a/admin/src/components/Table/index.tsx b/admin/src/components/Table/index.tsx index 6f2cb37e..f82c28b8 100644 --- a/admin/src/components/Table/index.tsx +++ b/admin/src/components/Table/index.tsx @@ -1,14 +1,19 @@ -import { ReactNode } from "react"; +import { ReactNode, RefObject, forwardRef } from "react"; interface TableProps { headers: ReactNode[]; data: ReactNode[][]; + height?: string | number; + dataLastItem?: RefObject; } -export default function Table({ headers, data }: TableProps) { +const Table = forwardRef(function Table( + { headers, data, height = 600, dataLastItem }, + ref +) { return ( -
-
+
+
@@ -32,9 +37,12 @@ export default function Table({ headers, data }: TableProps) { ))} ))} +
); -} +}); + +export default Table; diff --git a/admin/src/components/TextField/index.tsx b/admin/src/components/TextField/index.tsx new file mode 100644 index 00000000..3cfff79a --- /dev/null +++ b/admin/src/components/TextField/index.tsx @@ -0,0 +1,13 @@ +import { ComponentProps } from "react"; + +interface TextFieldProps extends ComponentProps<"textarea"> {} + +export default function TextField({ ...restProps }: TextFieldProps) { + return ( +