From 8b15dcebf8f37bd68c76f9618ffbec289966363e Mon Sep 17 00:00:00 2001 From: Sweli Giri Date: Tue, 15 Apr 2025 13:56:54 +0700 Subject: [PATCH] init project portal web --- Dockerfile | 35 + README.md | 121 +- app/api/cookies/route.ts | 10 + app/api/login/route.ts | 55 + app/api/logout/route.ts | 18 + app/api/priceplan-detail/usage-event/route.ts | 36 + app/api/priceplan/create/route.ts | 58 + app/api/priceplan/delete/route.ts | 36 + app/api/priceplan/menu/route.ts | 39 + app/api/priceplan/route.ts | 39 + app/api/priceplan/servetypes/route.ts | 36 + app/api/priceplan/types/route.ts | 36 + app/api/rate-plan/create/route.ts | 55 + app/favicon.ico | Bin 0 -> 25931 bytes app/globals.css | 98 + app/layout.tsx | 19 + app/main/layout.tsx | 15 + app/main/price-plan/[id]/page.tsx | 16 + app/main/price-plan/page.tsx | 9 + app/onboard/login/page.tsx | 10 + app/page.tsx | 11 + components.json | 21 + components/layout/main-layout/index.tsx | 38 + components/module/action-table/index.tsx | 38 + components/module/app-bar/index.tsx | 81 + components/module/backdrop/index.tsx | 28 + .../module/data-table-pagination/index.tsx | 97 + components/module/data-table/index.tsx | 150 + components/module/date-picker/index.tsx | 49 + components/module/dropdown/index.tsx | 201 + components/module/input-password/index.tsx | 27 + components/module/query-wrapper/index.tsx | 10 + .../sidebar/price-plan-sidebar/index.tsx | 78 + .../price-plan-sidebar/view-model/index.ts | 19 + components/ui/alert-dialog.tsx | 141 + components/ui/button.tsx | 57 + components/ui/calendar.tsx | 76 + components/ui/checkbox.tsx | 30 + components/ui/collapsible.tsx | 11 + components/ui/command.tsx | 153 + components/ui/dialog.tsx | 122 + components/ui/input.tsx | 22 + components/ui/label.tsx | 26 + components/ui/popover.tsx | 33 + components/ui/radio-group.tsx | 44 + components/ui/select.tsx | 159 + components/ui/separator.tsx | 31 + components/ui/sheet.tsx | 140 + components/ui/sidebar.tsx | 773 ++ components/ui/skeleton.tsx | 15 + components/ui/sonner.tsx | 31 + components/ui/table.tsx | 120 + components/ui/tabs.tsx | 55 + components/ui/tooltip.tsx | 32 + docker-compose.yml | 11 + hooks/use-mobile.tsx | 19 + images/Telkomcel.png | Bin 0 -> 20442 bytes images/ava.png | Bin 0 -> 4051 bytes images/export_icon.png | Bin 0 -> 307 bytes images/import_icon.png | Bin 0 -> 318 bytes images/left_clip_path.png | Bin 0 -> 76823 bytes images/login_accesoris.png | Bin 0 -> 1746 bytes images/logo.png | Bin 0 -> 2516 bytes images/logo_2.png | Bin 0 -> 1141 bytes images/right_clip_path.png | Bin 0 -> 96593 bytes lib/helper/option/index.ts | 12 + lib/helper/pagination/index.ts | 49 + lib/helper/query-data/index.ts | 38 + lib/helper/type/index.ts | 10 + lib/home/view/index.tsx | 90 + lib/login/data/repository/index.ts | 7 + lib/login/store/index.ts | 23 + lib/login/view-model/index.ts | 28 + lib/login/view/index.tsx | 110 + lib/price-plan-detail/constant/index.tsx | 26 + .../data/repository/index.ts | 16 + lib/price-plan-detail/mutation/index.ts | 16 + lib/price-plan-detail/queries/index.ts | 8 + .../state/price-plan-detail-state.ts | 76 + .../state/price-version-form-state.ts | 15 + .../state/rate-plan-form-state.ts | 50 + .../state/rate-plan-section-state.ts | 22 + lib/price-plan-detail/view-model/index.ts | 41 + .../view/data-table/index.tsx | 87 + .../dialog/price-version-dialog/index.tsx | 19 + .../view/dialog/rate-plan-dialog/index.tsx | 142 + .../view/dialog/usage-event-dialog/index.tsx | 72 + lib/price-plan-detail/view/header/index.tsx | 45 + lib/price-plan-detail/view/index.tsx | 41 + lib/price-plan-detail/view/tab/index.tsx | 38 + .../usage-content/flow/create-event/index.tsx | 31 + .../flow/create-rate-plan/index.tsx | 94 + .../view/tab/usage-content/flow/index.tsx | 24 + .../view/tab/usage-content/index.tsx | 32 + .../tab/usage-content/rate-plan/index.tsx | 78 + .../tab/usage-content/usage-events/index.tsx | 62 + lib/price-plan/constant/index.tsx | 65 + lib/price-plan/data/model/index.ts | 4 + lib/price-plan/data/repository/index.ts | 26 + lib/price-plan/model/menu-model.ts | 42 + lib/price-plan/model/price-plan-model.ts | 59 + lib/price-plan/mutations/index.ts | 28 + lib/price-plan/queries/index.ts | 20 + lib/price-plan/store/form-store.ts | 102 + lib/price-plan/store/index.ts | 55 + lib/price-plan/view-model/index.ts | 65 + .../view-model/sidebar-view-model.ts | 19 + lib/price-plan/view/combobox/index.tsx | 66 + lib/price-plan/view/data-table/index.tsx | 87 + lib/price-plan/view/index.tsx | 65 + .../view/modal-create-priceplan/index.tsx | 196 + lib/price-plan/view/sidebar/index.tsx | 92 + lib/utils.ts | 6 + middleware.ts | 10 + middleware/middleware.ts | 83 + next.config.mjs | 4 + package-lock.json | 7588 +++++++++++++++++ package.json | 54 + postcss.config.mjs | 8 + services/api/api-client.ts | 20 + tailwind.config.ts | 84 + tsconfig.json | 26 + 122 files changed, 13965 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 app/api/cookies/route.ts create mode 100644 app/api/login/route.ts create mode 100644 app/api/logout/route.ts create mode 100644 app/api/priceplan-detail/usage-event/route.ts create mode 100644 app/api/priceplan/create/route.ts create mode 100644 app/api/priceplan/delete/route.ts create mode 100644 app/api/priceplan/menu/route.ts create mode 100644 app/api/priceplan/route.ts create mode 100644 app/api/priceplan/servetypes/route.ts create mode 100644 app/api/priceplan/types/route.ts create mode 100644 app/api/rate-plan/create/route.ts create mode 100644 app/favicon.ico create mode 100644 app/globals.css create mode 100644 app/layout.tsx create mode 100644 app/main/layout.tsx create mode 100644 app/main/price-plan/[id]/page.tsx create mode 100644 app/main/price-plan/page.tsx create mode 100644 app/onboard/login/page.tsx create mode 100644 app/page.tsx create mode 100644 components.json create mode 100644 components/layout/main-layout/index.tsx create mode 100644 components/module/action-table/index.tsx create mode 100644 components/module/app-bar/index.tsx create mode 100644 components/module/backdrop/index.tsx create mode 100644 components/module/data-table-pagination/index.tsx create mode 100644 components/module/data-table/index.tsx create mode 100644 components/module/date-picker/index.tsx create mode 100644 components/module/dropdown/index.tsx create mode 100644 components/module/input-password/index.tsx create mode 100644 components/module/query-wrapper/index.tsx create mode 100644 components/module/sidebar/price-plan-sidebar/index.tsx create mode 100644 components/module/sidebar/price-plan-sidebar/view-model/index.ts create mode 100644 components/ui/alert-dialog.tsx create mode 100644 components/ui/button.tsx create mode 100644 components/ui/calendar.tsx create mode 100644 components/ui/checkbox.tsx create mode 100644 components/ui/collapsible.tsx create mode 100644 components/ui/command.tsx create mode 100644 components/ui/dialog.tsx create mode 100644 components/ui/input.tsx create mode 100644 components/ui/label.tsx create mode 100644 components/ui/popover.tsx create mode 100644 components/ui/radio-group.tsx create mode 100644 components/ui/select.tsx create mode 100644 components/ui/separator.tsx create mode 100644 components/ui/sheet.tsx create mode 100644 components/ui/sidebar.tsx create mode 100644 components/ui/skeleton.tsx create mode 100644 components/ui/sonner.tsx create mode 100644 components/ui/table.tsx create mode 100644 components/ui/tabs.tsx create mode 100644 components/ui/tooltip.tsx create mode 100644 docker-compose.yml create mode 100644 hooks/use-mobile.tsx create mode 100644 images/Telkomcel.png create mode 100644 images/ava.png create mode 100644 images/export_icon.png create mode 100644 images/import_icon.png create mode 100644 images/left_clip_path.png create mode 100644 images/login_accesoris.png create mode 100755 images/logo.png create mode 100755 images/logo_2.png create mode 100644 images/right_clip_path.png create mode 100644 lib/helper/option/index.ts create mode 100644 lib/helper/pagination/index.ts create mode 100644 lib/helper/query-data/index.ts create mode 100644 lib/helper/type/index.ts create mode 100644 lib/home/view/index.tsx create mode 100644 lib/login/data/repository/index.ts create mode 100644 lib/login/store/index.ts create mode 100644 lib/login/view-model/index.ts create mode 100644 lib/login/view/index.tsx create mode 100644 lib/price-plan-detail/constant/index.tsx create mode 100644 lib/price-plan-detail/data/repository/index.ts create mode 100644 lib/price-plan-detail/mutation/index.ts create mode 100644 lib/price-plan-detail/queries/index.ts create mode 100644 lib/price-plan-detail/state/price-plan-detail-state.ts create mode 100644 lib/price-plan-detail/state/price-version-form-state.ts create mode 100644 lib/price-plan-detail/state/rate-plan-form-state.ts create mode 100644 lib/price-plan-detail/state/rate-plan-section-state.ts create mode 100644 lib/price-plan-detail/view-model/index.ts create mode 100644 lib/price-plan-detail/view/data-table/index.tsx create mode 100644 lib/price-plan-detail/view/dialog/price-version-dialog/index.tsx create mode 100644 lib/price-plan-detail/view/dialog/rate-plan-dialog/index.tsx create mode 100644 lib/price-plan-detail/view/dialog/usage-event-dialog/index.tsx create mode 100644 lib/price-plan-detail/view/header/index.tsx create mode 100644 lib/price-plan-detail/view/index.tsx create mode 100644 lib/price-plan-detail/view/tab/index.tsx create mode 100644 lib/price-plan-detail/view/tab/usage-content/flow/create-event/index.tsx create mode 100644 lib/price-plan-detail/view/tab/usage-content/flow/create-rate-plan/index.tsx create mode 100644 lib/price-plan-detail/view/tab/usage-content/flow/index.tsx create mode 100644 lib/price-plan-detail/view/tab/usage-content/index.tsx create mode 100644 lib/price-plan-detail/view/tab/usage-content/rate-plan/index.tsx create mode 100644 lib/price-plan-detail/view/tab/usage-content/usage-events/index.tsx create mode 100644 lib/price-plan/constant/index.tsx create mode 100644 lib/price-plan/data/model/index.ts create mode 100644 lib/price-plan/data/repository/index.ts create mode 100644 lib/price-plan/model/menu-model.ts create mode 100644 lib/price-plan/model/price-plan-model.ts create mode 100644 lib/price-plan/mutations/index.ts create mode 100644 lib/price-plan/queries/index.ts create mode 100644 lib/price-plan/store/form-store.ts create mode 100644 lib/price-plan/store/index.ts create mode 100644 lib/price-plan/view-model/index.ts create mode 100644 lib/price-plan/view-model/sidebar-view-model.ts create mode 100644 lib/price-plan/view/combobox/index.tsx create mode 100644 lib/price-plan/view/data-table/index.tsx create mode 100644 lib/price-plan/view/index.tsx create mode 100644 lib/price-plan/view/modal-create-priceplan/index.tsx create mode 100644 lib/price-plan/view/sidebar/index.tsx create mode 100644 lib/utils.ts create mode 100644 middleware.ts create mode 100644 middleware/middleware.ts create mode 100644 next.config.mjs create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 postcss.config.mjs create mode 100644 services/api/api-client.ts create mode 100644 tailwind.config.ts create mode 100644 tsconfig.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a5d1f1a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Step 1: Build the application in a Node environment +FROM node:18 AS builder + +# Set the working directory +WORKDIR /app + +# Copy package.json and package-lock.json to install dependencies +COPY package.json package-lock.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the app's source code +COPY . . + +# Build the Next.js application for production +RUN npm run build + +# Step 2: Create a minimal production environment +FROM node:18-alpine + +# Set the working directory in the production container +WORKDIR /app + +# Copy only the necessary files from the builder stage +COPY --from=builder /app/package.json /app/package-lock.json ./ +COPY --from=builder /app/.next /app/.next +COPY --from=builder /app/public /app/public +COPY --from=builder /app/node_modules /app/node_modules + +# Expose the port the app will run on +EXPOSE 3000 + +# Start the app in production mode +CMD ["npm", "run", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 351e5f5..0e469e5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,121 @@ -# ocs-portal-web +# Project Next.js 14 dengan Zustand, React Query (TanStack), dan ShadCN +## 📌 Pendahuluan +Proyek ini menggunakan **Next.js 14** sebagai kerangka kerja utama, dengan **Zustand** untuk manajemen state, **React Query (TanStack)** untuk pengelolaan data asinkron, dan **ShadCN** untuk komponen UI yang modern dan fleksibel. + +## 🛠️ Teknologi yang Digunakan +- [Next.js 14](https://nextjs.org/) - Framework React untuk aplikasi web modern. +- [Zustand](https://zustand-demo.pmnd.rs/) - Manajemen state yang ringan dan fleksibel. +- [React Query (TanStack)](https://tanstack.com/query/latest) - Manajemen data server-side yang efisien. +- [ShadCN](https://ui.shadcn.com/) - Komponen UI berbasis Radix dan Tailwind CSS. + +## 🚀 Instalasi +Pastikan Anda sudah menginstal **Node.js** dan **pnpm/npm/yarn** sebelum memulai. + +1. Clone repositori ini: + ```sh + git clone https://github.com/username/repository.git + cd repository + ``` + +2. Install dependensi: + ```sh + pnpm install # atau npm install / yarn install + ``` + +3. Jalankan proyek dalam mode pengembangan: + ```sh + pnpm dev # atau npm run dev / yarn dev + ``` + +4. Buka browser dan akses **http://localhost:3000**. + +## 🏗️ Penggunaan +### Manajemen State dengan Zustand +Buat file di `store/useExampleStore.ts`: +```ts +import { create } from 'zustand'; + +type ExampleState = { + count: number; + increment: () => void; +}; + +export const useExampleStore = create((set) => ({ + count: 0, + increment: () => set((state) => ({ count: state.count + 1 })), +})); +``` +Penggunaan dalam komponen: +```tsx +import { useExampleStore } from '@/store/useExampleStore'; + +export default function Counter() { + const { count, increment } = useExampleStore(); + return ( +
+

Count: {count}

+ +
+ ); +} +``` + +### Fetching Data dengan React Query (TanStack) +Buat file di `lib/api.ts`: +```ts +export const fetchData = async () => { + const res = await fetch('https://jsonplaceholder.typicode.com/posts'); + if (!res.ok) throw new Error('Gagal mengambil data'); + return res.json(); +}; +``` +Penggunaan dalam komponen: +```tsx +import { useQuery } from '@tanstack/react-query'; +import { fetchData } from '@/lib/api'; + +export default function DataList() { + const { data, error, isLoading } = useQuery({ queryKey: ['posts'], queryFn: fetchData }); + + if (isLoading) return

Loading...

; + if (error) return

Error: {error.message}

; + + return ( + + ); +} +``` + +### Menggunakan Komponen UI dari ShadCN +Pastikan telah menginstal ShadCN: +```sh +pnpm dlx shadcn-ui@latest init +``` +Contoh penggunaan tombol: +```tsx +import { Button } from '@/components/ui/button'; + +export default function ExampleButton() { + return ; +} +``` + +## ✅ TODO +- [x] Setup Next.js 14 +- [x] Integrasi Zustand untuk state management +- [x] Implementasi React Query (TanStack) untuk fetching data +- [x] Konfigurasi ShadCN untuk komponen UI +- [ ] Tambahkan autentikasi dengan NextAuth +- [ ] Implementasi dark mode + +## 📜 Lisensi +Proyek ini dilisensikan di bawah [MIT License](LICENSE). + +--- + +Selamat ngoding! 🚀 \ No newline at end of file diff --git a/app/api/cookies/route.ts b/app/api/cookies/route.ts new file mode 100644 index 0000000..824a0f7 --- /dev/null +++ b/app/api/cookies/route.ts @@ -0,0 +1,10 @@ +import { NextResponse } from "next/server"; +import { cookies } from "next/headers"; + +export async function GET() { + const cookieStore = cookies(); + const credential = JSON.parse(cookieStore.get("credential")?.value || ""); + + + return NextResponse.json({ credential }); +} \ No newline at end of file diff --git a/app/api/login/route.ts b/app/api/login/route.ts new file mode 100644 index 0000000..bfe8f2a --- /dev/null +++ b/app/api/login/route.ts @@ -0,0 +1,55 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextRequest, NextResponse } from 'next/server'; + +export const POST = async (request: NextRequest) => { + // INTERPOLATING API URL OF BACKEND + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/auth/login` + // GET REQUEST BODY + const {username, password} = await request.json(); + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + data: JSON.stringify({ + userName: username, + password, + }) + }) + + + if (response?.data ?? false) { + const token: string = response.data.data.token; + const expired = response.data.data.expired; + const data = { + username: response.data.data.username, + token + } + cookies().set({ + name: 'credential', + value: JSON.stringify(data), + httpOnly: false, + sameSite: 'strict', + path: '/', + maxAge: expired + }) + } + return NextResponse.json(response.data, { status: response.status }); + } catch (error: unknown) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/logout/route.ts b/app/api/logout/route.ts new file mode 100644 index 0000000..c6e7017 --- /dev/null +++ b/app/api/logout/route.ts @@ -0,0 +1,18 @@ +import { cookies } from 'next/headers'; +import { NextResponse } from 'next/server'; + +export const POST = async () => { + // Hapus cookie 'credential' + cookies().delete({ + name: "credential", + httpOnly: false, + sameSite: 'strict', + path: '/', + maxAge: 0, + }) + // Return a JSON response + return NextResponse.json({ + message: 'Cookie deleted successfully.', + status: 'success', + }, { status: 200 }); +}; diff --git a/app/api/priceplan-detail/usage-event/route.ts b/app/api/priceplan-detail/usage-event/route.ts new file mode 100644 index 0000000..51ff698 --- /dev/null +++ b/app/api/priceplan-detail/usage-event/route.ts @@ -0,0 +1,36 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextResponse } from 'next/server'; + +export const POST = async () => { + // INTERPOLATING API URL OF BACKEND + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/usage_event/list` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/priceplan/create/route.ts b/app/api/priceplan/create/route.ts new file mode 100644 index 0000000..0af11c0 --- /dev/null +++ b/app/api/priceplan/create/route.ts @@ -0,0 +1,58 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextRequest, NextResponse } from 'next/server'; + +export const POST = async (request: NextRequest) => { + // INTERPOLATING API URL OF BACKEND + const { + offerType, + offerName, + pricePlanCode, + remarks, + sourceFrom, + baseValidPeriod, + serviceType, + versionValidPeriod + } = await request.json(); + + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/createpriceplan` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + data: JSON.stringify({ + offerType, + offerName, + applyLevel: "S", + pricePlanCode, + remarks, + sourceFrom, + baseValidPeriod, + versionValidPeriod, + serviceType + }) + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/priceplan/delete/route.ts b/app/api/priceplan/delete/route.ts new file mode 100644 index 0000000..a0923f6 --- /dev/null +++ b/app/api/priceplan/delete/route.ts @@ -0,0 +1,36 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextRequest, NextResponse } from 'next/server'; + +export const POST = async (request: NextRequest) => { + // INTERPOLATING API URL OF BACKEND + const {id} = await request.json(); + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/delete/${id}` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'DELETE', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + }) + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/priceplan/menu/route.ts b/app/api/priceplan/menu/route.ts new file mode 100644 index 0000000..4c3ccd0 --- /dev/null +++ b/app/api/priceplan/menu/route.ts @@ -0,0 +1,39 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextResponse } from 'next/server'; + +export const POST = async () => { + // INTERPOLATING API URL OF BACKEND + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/getmenuList` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + // console.log(token, 'cek token'); + + + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/priceplan/route.ts b/app/api/priceplan/route.ts new file mode 100644 index 0000000..fecccf0 --- /dev/null +++ b/app/api/priceplan/route.ts @@ -0,0 +1,39 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextRequest, NextResponse } from 'next/server'; + +export const POST = async (request: NextRequest) => { + // INTERPOLATING API URL OF BACKEND + const {page, size, type} = await request.json(); + let url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/list` + if(type) url += `/${type}` + url += `?page=${page}&size=${size}` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/priceplan/servetypes/route.ts b/app/api/priceplan/servetypes/route.ts new file mode 100644 index 0000000..78e86bf --- /dev/null +++ b/app/api/priceplan/servetypes/route.ts @@ -0,0 +1,36 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextResponse } from 'next/server'; + +export const POST = async () => { + // INTERPOLATING API URL OF BACKEND + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/getservtype` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/priceplan/types/route.ts b/app/api/priceplan/types/route.ts new file mode 100644 index 0000000..72187df --- /dev/null +++ b/app/api/priceplan/types/route.ts @@ -0,0 +1,36 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextResponse } from 'next/server'; + +export const POST = async () => { + // INTERPOLATING API URL OF BACKEND + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/getalltype` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/api/rate-plan/create/route.ts b/app/api/rate-plan/create/route.ts new file mode 100644 index 0000000..13224eb --- /dev/null +++ b/app/api/rate-plan/create/route.ts @@ -0,0 +1,55 @@ +import axios from 'axios'; +import { cookies } from 'next/headers' +import { NextRequest, NextResponse } from 'next/server'; + +export const POST = async (request: NextRequest) => { + // INTERPOLATING API URL OF BACKEND + const { + offerVerId, + offerType, + reId, + ratePlanName, + ratePlanCode, + remarks, + ratePlanType, + } = await request.json(); + + const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/createpriceplan` + const data = JSON.parse(cookies().get('credential')?.value ?? "") + const token = `Bearer ${data.token}` + + try { + // MAKE AN API REQUEST + /* + * - WE USE AXIOS INSTEAD OF FETCH + * - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed" + * WHEN WE RUN "response.json()" + */ + const response = await axios(url, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': token + }, + data: JSON.stringify({ + offerVerId, + offerType, + reId, + ratePlanName, + ratePlanCode, + remarks, + ratePlanType, + }) + }) + + + return NextResponse.json(response.data, { status: response.status }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 }); + } + return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 }); + + } +} \ No newline at end of file diff --git a/app/favicon.ico b/app/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..718d6fea4835ec2d246af9800eddb7ffb276240c GIT binary patch literal 25931 zcmeHv30#a{`}aL_*G&7qml|y<+KVaDM2m#dVr!KsA!#An?kSQM(q<_dDNCpjEux83 zLb9Z^XxbDl(w>%i@8hT6>)&Gu{h#Oeyszu?xtw#Zb1mO{pgX9699l+Qppw7jXaYf~-84xW z)w4x8?=youko|}Vr~(D$UXIbiXABHh`p1?nn8Po~fxRJv}|0e(BPs|G`(TT%kKVJAdg5*Z|x0leQq0 zkdUBvb#>9F()jo|T~kx@OM8$9wzs~t2l;K=woNssA3l6|sx2r3+kdfVW@e^8e*E}v zA1y5{bRi+3Z`uD3{F7LgFJDdvm;nJilkzDku>BwXH(8ItVCXk*-lSJnR?-2UN%hJ){&rlvg`CDTj z)Bzo!3v7Ou#83zEDEFcKt(f1E0~=rqeEbTnMvWR#{+9pg%7G8y>u1OVRUSoox-ovF z2Ydma(;=YuBY(eI|04{hXzZD6_f(v~H;C~y5=DhAC{MMS>2fm~1H_t2$56pc$NH8( z5bH|<)71dV-_oCHIrzrT`2s-5w_+2CM0$95I6X8p^r!gHp+j_gd;9O<1~CEQQGS8) zS9Qh3#p&JM-G8rHekNmKVewU;pJRcTAog68KYo^dRo}(M>36U4Us zfgYWSiHZL3;lpWT=zNAW>Dh#mB!_@Lg%$ms8N-;aPqMn+C2HqZgz&9~Eu z4|Kp<`$q)Uw1R?y(~S>ePdonHxpV1#eSP1B;Ogo+-Pk}6#0GsZZ5!||ev2MGdh}_m z{DeR7?0-1^zVs&`AV6Vt;r3`I`OI_wgs*w=eO%_#7Kepl{B@xiyCANc(l zzIyd4y|c6PXWq9-|KM8(zIk8LPk(>a)zyFWjhT!$HJ$q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mHP#8S)*2U~QKI%S zyrLmtPqb&TphJ;>yAxri#;{uyk`JJqODDw%(Z=2`1uc}br^V%>j!gS)D*q*f_-qf8&D;W1dJgQMlaH5er zN2U<%Smb7==vE}dDI8K7cKz!vs^73o9f>2sgiTzWcwY|BMYHH5%Vn7#kiw&eItCqa zIkR2~Q}>X=Ar8W|^Ms41Fm8o6IB2_j60eOeBB1Br!boW7JnoeX6Gs)?7rW0^5psc- zjS16yb>dFn>KPOF;imD}e!enuIniFzv}n$m2#gCCv4jM#ArwlzZ$7@9&XkFxZ4n!V zj3dyiwW4Ki2QG{@i>yuZXQizw_OkZI^-3otXC{!(lUpJF33gI60ak;Uqitp74|B6I zgg{b=Iz}WkhCGj1M=hu4#Aw173YxIVbISaoc z-nLZC*6Tgivd5V`K%GxhBsp@SUU60-rfc$=wb>zdJzXS&-5(NRRodFk;Kxk!S(O(a0e7oY=E( zAyS;Ow?6Q&XA+cnkCb{28_1N8H#?J!*$MmIwLq^*T_9-z^&UE@A(z9oGYtFy6EZef LrJugUA?W`A8`#=m literal 0 HcmV?d00001 diff --git a/app/globals.css b/app/globals.css new file mode 100644 index 0000000..da6c12b --- /dev/null +++ b/app/globals.css @@ -0,0 +1,98 @@ +@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap'); + +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer utilities { + .text-balance { + text-wrap: balance; + } +} + + + +@layer base { + :root { + --background: 0 0% 100%; + --foreground: 0 0% 3.9%; + --card: 0 0% 100%; + --card-foreground: 0 0% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 0 0% 3.9%; + --primary: 0 0% 9%; + --primary-foreground: 0 0% 98%; + --secondary: 0 0% 96.1%; + --secondary-foreground: 0 0% 9%; + --muted: 0 0% 96.1%; + --muted-foreground: 0 0% 45.1%; + --accent: 0 0% 96.1%; + --accent-foreground: 0 0% 9%; + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 0 0% 98%; + --border: 0 0% 89.8%; + --input: 0 0% 89.8%; + --ring: 0 0% 3.9%; + --chart-1: 12 76% 61%; + --chart-2: 173 58% 39%; + --chart-3: 197 37% 24%; + --chart-4: 43 74% 66%; + --chart-5: 27 87% 67%; + --radius: 0.5rem; + --sidebar-background: 189 100% 31%; + --sidebar-foreground: 0 0% 98%; + --sidebar-primary: 240 5.9% 10%; + --sidebar-primary-foreground: 0 0% 98%; + --sidebar-accent: 240 4.8% 95.9%; + --sidebar-accent-foreground: 240 5.9% 10%; + --sidebar-border: 220 13% 91%; + --sidebar-ring: 217.2 91.2% 59.8%; + } + .dark { + --background: 0 0% 3.9%; + --foreground: 0 0% 98%; + --card: 0 0% 3.9%; + --card-foreground: 0 0% 98%; + --popover: 0 0% 3.9%; + --popover-foreground: 0 0% 98%; + --primary: 0 0% 98%; + --primary-foreground: 0 0% 9%; + --secondary: 0 0% 14.9%; + --secondary-foreground: 0 0% 98%; + --muted: 0 0% 14.9%; + --muted-foreground: 0 0% 63.9%; + --accent: 0 0% 14.9%; + --accent-foreground: 0 0% 98%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 0% 98%; + --border: 0 0% 14.9%; + --input: 0 0% 14.9%; + --ring: 0 0% 83.1%; + --chart-1: 220 70% 50%; + --chart-2: 160 60% 45%; + --chart-3: 30 80% 55%; + --chart-4: 280 65% 60%; + --chart-5: 340 75% 55%; + --sidebar-background: 240 5.9% 10%; + --sidebar-foreground: 240 4.8% 95.9%; + --sidebar-primary: 224.3 76.3% 48%; + --sidebar-primary-foreground: 0 0% 100%; + --sidebar-accent: 240 3.7% 15.9%; + --sidebar-accent-foreground: 240 4.8% 95.9%; + --sidebar-border: 240 3.7% 15.9%; + --sidebar-ring: 217.2 91.2% 59.8%; + } +} + + + +@layer base { + * { + @apply border-border; + } + body { + @apply bg-background text-foreground; + font-family: "Outfit", sans-serif; + box-sizing: border-box; + } +} diff --git a/app/layout.tsx b/app/layout.tsx new file mode 100644 index 0000000..7803041 --- /dev/null +++ b/app/layout.tsx @@ -0,0 +1,19 @@ +import type { Metadata } from "next"; +import "./globals.css"; + +export const metadata: Metadata = { + title: "OCS Portal Web", + description: "Generated by create next app", +}; + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( + + {children} + + ); +} diff --git a/app/main/layout.tsx b/app/main/layout.tsx new file mode 100644 index 0000000..aac5ee4 --- /dev/null +++ b/app/main/layout.tsx @@ -0,0 +1,15 @@ +import MainLayout from "@/components/layout/main-layout" + +interface Props { + children: React.ReactNode +} + +const Layout = ({ + children +}: Props) => { + return ( + {children} + ) +} + +export default Layout \ No newline at end of file diff --git a/app/main/price-plan/[id]/page.tsx b/app/main/price-plan/[id]/page.tsx new file mode 100644 index 0000000..6b612b4 --- /dev/null +++ b/app/main/price-plan/[id]/page.tsx @@ -0,0 +1,16 @@ +import PricePlanDetail from "@/lib/price-plan-detail/view" + +interface Props { + params: { + id: string + } + } + +const Page = ({params}: Props) => { + const id = params.id + return ( + + ) +} + +export default Page \ No newline at end of file diff --git a/app/main/price-plan/page.tsx b/app/main/price-plan/page.tsx new file mode 100644 index 0000000..db9465b --- /dev/null +++ b/app/main/price-plan/page.tsx @@ -0,0 +1,9 @@ +import PricePlanList from "@/lib/price-plan/view" + +const PricePlan = () => { + return ( + + ) +} + +export default PricePlan \ No newline at end of file diff --git a/app/onboard/login/page.tsx b/app/onboard/login/page.tsx new file mode 100644 index 0000000..3b029e5 --- /dev/null +++ b/app/onboard/login/page.tsx @@ -0,0 +1,10 @@ +import Login from "@/lib/login/view" + + +const LoginPage = () => { + return ( + + ) +} + +export default LoginPage \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx new file mode 100644 index 0000000..afe8ab7 --- /dev/null +++ b/app/page.tsx @@ -0,0 +1,11 @@ +import AppBar from "@/components/module/app-bar" +import HomeView from "@/lib/home/view" + +export default function homePage() { + return ( +
+ + +
+ ) +} \ No newline at end of file diff --git a/components.json b/components.json new file mode 100644 index 0000000..dea737b --- /dev/null +++ b/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "new-york", + "rsc": true, + "tsx": true, + "tailwind": { + "config": "tailwind.config.ts", + "css": "app/globals.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils", + "ui": "@/components/ui", + "lib": "@/lib", + "hooks": "@/hooks" + }, + "iconLibrary": "lucide" +} \ No newline at end of file diff --git a/components/layout/main-layout/index.tsx b/components/layout/main-layout/index.tsx new file mode 100644 index 0000000..65d323e --- /dev/null +++ b/components/layout/main-layout/index.tsx @@ -0,0 +1,38 @@ +"use client" + +import AppBar from "@/components/module/app-bar" +import { SidebarProvider } from "@/components/ui/sidebar" +import PricePlanSidebar from "@/lib/price-plan/view/sidebar" +import { usePathname } from "next/navigation" +import React from "react" +import { Toaster } from "sonner" + +interface Props { + children: React.ReactNode +} + +const MainLayout = ({ + children +}: Props) => { + const pathname = usePathname() + const match = pathname.match(/\/price-plan\/(\d+)/) + + return ( + + {!match && } +
+ +
+ {children} +
+
+ +
+ ) +} + +export default MainLayout \ No newline at end of file diff --git a/components/module/action-table/index.tsx b/components/module/action-table/index.tsx new file mode 100644 index 0000000..94ee291 --- /dev/null +++ b/components/module/action-table/index.tsx @@ -0,0 +1,38 @@ +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Download, Filter, Plus, Upload } from "lucide-react" + +interface Props { + onClickNew: () => void +} + +const ActionTable = ({ + onClickNew +}: Props) => { + return ( +
+ + + + + +
+ ) +} + +export default ActionTable \ No newline at end of file diff --git a/components/module/app-bar/index.tsx b/components/module/app-bar/index.tsx new file mode 100644 index 0000000..7436c93 --- /dev/null +++ b/components/module/app-bar/index.tsx @@ -0,0 +1,81 @@ +"use client" +import { loginRepository } from "@/lib/login/data/repository" +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu" +import { useMutation } from "@tanstack/react-query" +import QueryWrapper from "../query-wrapper" +import { useRouter } from "next/navigation" +import logo_2 from "@/images/Telkomcel.png" +import ava from "@/images/ava.png" +import Image from "next/image" +import { useEffect, useState } from "react" + +interface Props { + useLogo: boolean +} + +const Content = ({ + useLogo +}: Props) => { + const [username, setUserName] = useState(""); + const router = useRouter() + const mutation = useMutation({ + mutationFn: () => loginRepository.logout(), + onSuccess: () => { + router.push("/onboard/login") + }, + onError: () => { + console.log('error') + }, + }) + + useEffect(() => { + fetch("/api/cookies") + .then((res) => res.json()) + .then((data) => setUserName(data.credential.username)); + }, []); + + return ( +
+ {useLogo ?
+
+ logo_2 +
+
:
} +
+ + +
+
+

Welcome,

+

{username}

+
+ ava +
+
+ + + + + + + + +
+
+
+ ) +} + +const AppBar = ({useLogo = true}: {useLogo: boolean}) => { + return ( + + + + ) +} + +export default AppBar \ No newline at end of file diff --git a/components/module/backdrop/index.tsx b/components/module/backdrop/index.tsx new file mode 100644 index 0000000..eae2537 --- /dev/null +++ b/components/module/backdrop/index.tsx @@ -0,0 +1,28 @@ +import { ReactNode } from "react" + +interface BackdropProps { + isOpen: boolean + onClose?: () => void + children: ReactNode +} + +const Backdrop = ({ isOpen, onClose, children }: BackdropProps) => { + if (!isOpen) return null + + return ( +
+ {/* Backdrop layer */} +
+ + {/* Dialog content */} +
+ {children} +
+
+ ) +} + +export default Backdrop diff --git a/components/module/data-table-pagination/index.tsx b/components/module/data-table-pagination/index.tsx new file mode 100644 index 0000000..2f3a6df --- /dev/null +++ b/components/module/data-table-pagination/index.tsx @@ -0,0 +1,97 @@ +import { Table } from "@tanstack/react-table" +import { + ChevronLeft, + ChevronRight, + ChevronsLeft, + ChevronsRight, +} from "lucide-react" + +import { Button } from "@/components/ui/button" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" + +interface DataTablePaginationProps { + table: Table +} + +export function DataTablePagination({ + table, +}: DataTablePaginationProps) { + return ( +
+
+ {table.getFilteredSelectedRowModel().rows.length} of{" "} + {table.getFilteredRowModel().rows.length} row(s) selected. +
+
+
+

Rows per page

+ +
+
+ Page {table.getState().pagination.pageIndex + 1} of{" "} + {table.getPageCount()} +
+
+ + + + +
+
+
+ ) +} diff --git a/components/module/data-table/index.tsx b/components/module/data-table/index.tsx new file mode 100644 index 0000000..08138c9 --- /dev/null +++ b/components/module/data-table/index.tsx @@ -0,0 +1,150 @@ +"use client"; + +import { + ColumnDef, + flexRender, + getCoreRowModel, + getPaginationRowModel, + useReactTable, +} from "@tanstack/react-table" + +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table" +import { DataTablePagination } from "../data-table-pagination"; +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; + +interface PaginationState { + pageIndex: number + pageSize: number + pageCount: number + setPageIndex: (page: number) => void + setPageSize: (size: number) => void +} + +interface AlertDialogState { + isOpen: boolean + title?: string + description?: string + confirmText?: string + cancelText?: string + setOpen: (isOpen: boolean) => void + onConfirm: () => void + onCancel: () => void +} + +interface DataTableProps { + columns: ColumnDef[] + data: TData[] + pagination?: PaginationState, + alertDialog?: AlertDialogState, +} + +const DataTable = ({ + data, + columns, + pagination, + alertDialog +}: DataTableProps) => { + const table = useReactTable({ + data, + columns, + pageCount: pagination?.pageCount, + state: { + pagination: { + pageIndex: pagination?.pageIndex ?? 0, + pageSize: pagination?.pageSize ?? 10, + }, + }, + onPaginationChange: (updater) => { + if (!pagination) return; + const next = typeof updater === 'function' + ? updater({ pageIndex: pagination.pageIndex, pageSize: pagination.pageSize }) + : updater; + pagination.setPageIndex(next.pageIndex) + pagination.setPageSize(next.pageSize) + }, + manualPagination: true, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + }) + + return ( +
+
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header, index) => { + const isFirst = index === 0; + const isLast = index === headerGroup.headers.length - 1; + return ( + + {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )} + + ) + })} + + ))} + + + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ))} + + )) + ) : ( + + + No results. + + + )} + +
+
+ + + + + Are you absolutely sure? + + This action cannot be undone. This will permanently remove your data + from our servers. + + + + Cancel + Continue + + + + +
+ ) + +} + +export default DataTable \ No newline at end of file diff --git a/components/module/date-picker/index.tsx b/components/module/date-picker/index.tsx new file mode 100644 index 0000000..42fc059 --- /dev/null +++ b/components/module/date-picker/index.tsx @@ -0,0 +1,49 @@ +import { Button } from "@/components/ui/button" +import { Calendar } from "@/components/ui/calendar" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" +import { cn } from "@/lib/utils" +import { format } from "date-fns" +import { CalendarIcon } from "lucide-react" +import React from "react" + +export function DatePicker({ + value, + onChange, + placeholder = "Select Date", + }: { + value?: Date, + placeholder?: string, + onChange?: (date: Date | undefined) => void + }) { + const [date, setDate] = React.useState(value) + + React.useEffect(() => { + if (onChange) onChange(date) + }, [date]) + + return ( + + + + + + + + + ) + } + \ No newline at end of file diff --git a/components/module/dropdown/index.tsx b/components/module/dropdown/index.tsx new file mode 100644 index 0000000..5a20503 --- /dev/null +++ b/components/module/dropdown/index.tsx @@ -0,0 +1,201 @@ +"use client" + +import * as React from "react" +import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu" +import { Check, ChevronRight, Circle } from "lucide-react" + +import { cn } from "@/lib/utils" + +const DropdownMenu = DropdownMenuPrimitive.Root + +const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger + +const DropdownMenuGroup = DropdownMenuPrimitive.Group + +const DropdownMenuPortal = DropdownMenuPrimitive.Portal + +const DropdownMenuSub = DropdownMenuPrimitive.Sub + +const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup + +const DropdownMenuSubTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & { + inset?: boolean + } +>(({ className, inset, children, ...props }, ref) => ( + + {children} + + +)) +DropdownMenuSubTrigger.displayName = + DropdownMenuPrimitive.SubTrigger.displayName + +const DropdownMenuSubContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DropdownMenuSubContent.displayName = + DropdownMenuPrimitive.SubContent.displayName + +const DropdownMenuContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, sideOffset = 4, ...props }, ref) => ( + + + +)) +DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName + +const DropdownMenuItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & { + inset?: boolean + } +>(({ className, inset, ...props }, ref) => ( + svg]:size-4 [&>svg]:shrink-0", + inset && "pl-8", + className + )} + {...props} + /> +)) +DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName + +const DropdownMenuCheckboxItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, checked, ...props }, ref) => ( + + + + + + + {children} + +)) +DropdownMenuCheckboxItem.displayName = + DropdownMenuPrimitive.CheckboxItem.displayName + +const DropdownMenuRadioItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + + + + {children} + +)) +DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName + +const DropdownMenuLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & { + inset?: boolean + } +>(({ className, inset, ...props }, ref) => ( + +)) +DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName + +const DropdownMenuSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName + +const DropdownMenuShortcut = ({ + className, + ...props +}: React.HTMLAttributes) => { + return ( + + ) +} +DropdownMenuShortcut.displayName = "DropdownMenuShortcut" + +export { + DropdownMenu, + DropdownMenuTrigger, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuCheckboxItem, + DropdownMenuRadioItem, + DropdownMenuLabel, + DropdownMenuSeparator, + DropdownMenuShortcut, + DropdownMenuGroup, + DropdownMenuPortal, + DropdownMenuSub, + DropdownMenuSubContent, + DropdownMenuSubTrigger, + DropdownMenuRadioGroup, +} diff --git a/components/module/input-password/index.tsx b/components/module/input-password/index.tsx new file mode 100644 index 0000000..c082a23 --- /dev/null +++ b/components/module/input-password/index.tsx @@ -0,0 +1,27 @@ +import { useState } from "react"; +import { Eye, EyeOff } from "lucide-react"; +import { Input } from "@/components/ui/input"; + +interface Props extends React.InputHTMLAttributes {} + +const InputPassword = ({ ...props }: Props) => { + const [showPassword, setShowPassword] = useState(false); + + return ( +
+ + +
+ ); +}; + +export default InputPassword; \ No newline at end of file diff --git a/components/module/query-wrapper/index.tsx b/components/module/query-wrapper/index.tsx new file mode 100644 index 0000000..2ec9472 --- /dev/null +++ b/components/module/query-wrapper/index.tsx @@ -0,0 +1,10 @@ +'use client'; + +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +// import { useState } from 'react'; + +export default function QueryWrapper({ children }: { children: React.ReactNode }) { + const queryClient = new QueryClient() + + return {children}; +} \ No newline at end of file diff --git a/components/module/sidebar/price-plan-sidebar/index.tsx b/components/module/sidebar/price-plan-sidebar/index.tsx new file mode 100644 index 0000000..139b350 --- /dev/null +++ b/components/module/sidebar/price-plan-sidebar/index.tsx @@ -0,0 +1,78 @@ +"use client" + +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" +import { Sidebar, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar" +import { ChevronDown, DollarSign, LayoutDashboard } from "lucide-react" +import mainLogo from "@/images/logo.png" +import Image from "next/image" +import QueryWrapper from "@/components/module/query-wrapper" +import { useMenuPricePlan } from "./view-model" +import Link from "next/link" + +const Content = () => { + const vm = useMenuPricePlan() + + return ( +
+ + +
+ main-logo +

NetworkPro

+
+
+ + + + + + Dashboard + + + + + {vm.getData().map((item, idx) => ( + + + + + + + {item.getParentName() === "S" ? "Subscribe" : item.getParentName()} + + + + + + + + + {item.getPricePlanTypeDto().map((item) => ( + + + + - + {item.pricePlanTypeName} + + + + ))} + + + + + ))} +
+
+ ) +} + +const PricePlanSidebar = () => { + return ( + + + + ) +} + +export default PricePlanSidebar \ No newline at end of file diff --git a/components/module/sidebar/price-plan-sidebar/view-model/index.ts b/components/module/sidebar/price-plan-sidebar/view-model/index.ts new file mode 100644 index 0000000..d63f517 --- /dev/null +++ b/components/module/sidebar/price-plan-sidebar/view-model/index.ts @@ -0,0 +1,19 @@ +import CommonData from "@/lib/helper/query-data" +import { pricePlanRepository } from "@/lib/price-plan/data/repository" +import { PricePlanMenuModel } from "@/lib/price-plan/model/menu-model" +import { useQuery } from "@tanstack/react-query" + +export const useMenuPricePlan = () => { + const query = useQuery({ + queryKey: ["priceplan-menu"], + queryFn: pricePlanRepository.getMenuList, + }) + + return new CommonData({ + isLoading: query.isLoading, + isError: query.isError, + error: query.error, + data: query.data ? PricePlanMenuModel.fromJSON(query.data) : [], + extra: null + }) +} \ No newline at end of file diff --git a/components/ui/alert-dialog.tsx b/components/ui/alert-dialog.tsx new file mode 100644 index 0000000..57760f2 --- /dev/null +++ b/components/ui/alert-dialog.tsx @@ -0,0 +1,141 @@ +"use client" + +import * as React from "react" +import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog" + +import { cn } from "@/lib/utils" +import { buttonVariants } from "@/components/ui/button" + +const AlertDialog = AlertDialogPrimitive.Root + +const AlertDialogTrigger = AlertDialogPrimitive.Trigger + +const AlertDialogPortal = AlertDialogPrimitive.Portal + +const AlertDialogOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName + +const AlertDialogContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + + +)) +AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName + +const AlertDialogHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +AlertDialogHeader.displayName = "AlertDialogHeader" + +const AlertDialogFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +AlertDialogFooter.displayName = "AlertDialogFooter" + +const AlertDialogTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName + +const AlertDialogDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogDescription.displayName = + AlertDialogPrimitive.Description.displayName + +const AlertDialogAction = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName + +const AlertDialogCancel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName + +export { + AlertDialog, + AlertDialogPortal, + AlertDialogOverlay, + AlertDialogTrigger, + AlertDialogContent, + AlertDialogHeader, + AlertDialogFooter, + AlertDialogTitle, + AlertDialogDescription, + AlertDialogAction, + AlertDialogCancel, +} diff --git a/components/ui/button.tsx b/components/ui/button.tsx new file mode 100644 index 0000000..65d4fcd --- /dev/null +++ b/components/ui/button.tsx @@ -0,0 +1,57 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const buttonVariants = cva( + "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", + { + variants: { + variant: { + default: + "bg-primary text-primary-foreground shadow hover:bg-primary/90", + destructive: + "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90", + outline: + "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground", + secondary: + "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-9 px-4 py-2", + sm: "h-8 rounded-md px-3 text-xs", + lg: "h-10 rounded-md px-8", + icon: "h-9 w-9", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean +} + +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button" + return ( + + ) + } +) +Button.displayName = "Button" + +export { Button, buttonVariants } diff --git a/components/ui/calendar.tsx b/components/ui/calendar.tsx new file mode 100644 index 0000000..115cff9 --- /dev/null +++ b/components/ui/calendar.tsx @@ -0,0 +1,76 @@ +"use client" + +import * as React from "react" +import { ChevronLeft, ChevronRight } from "lucide-react" +import { DayPicker } from "react-day-picker" + +import { cn } from "@/lib/utils" +import { buttonVariants } from "@/components/ui/button" + +export type CalendarProps = React.ComponentProps + +function Calendar({ + className, + classNames, + showOutsideDays = true, + ...props +}: CalendarProps) { + return ( + .day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md" + : "[&:has([aria-selected])]:rounded-md" + ), + day: cn( + buttonVariants({ variant: "ghost" }), + "h-8 w-8 p-0 font-normal aria-selected:opacity-100" + ), + day_range_start: "day-range-start", + day_range_end: "day-range-end", + day_selected: + "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground", + day_today: "bg-accent text-accent-foreground", + day_outside: + "day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground", + day_disabled: "text-muted-foreground opacity-50", + day_range_middle: + "aria-selected:bg-accent aria-selected:text-accent-foreground", + day_hidden: "invisible", + ...classNames, + }} + components={{ + IconLeft: ({ className, ...props }) => ( + + ), + IconRight: ({ className, ...props }) => ( + + ), + }} + {...props} + /> + ) +} +Calendar.displayName = "Calendar" + +export { Calendar } diff --git a/components/ui/checkbox.tsx b/components/ui/checkbox.tsx new file mode 100644 index 0000000..c6fdd07 --- /dev/null +++ b/components/ui/checkbox.tsx @@ -0,0 +1,30 @@ +"use client" + +import * as React from "react" +import * as CheckboxPrimitive from "@radix-ui/react-checkbox" +import { Check } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Checkbox = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + + + +)) +Checkbox.displayName = CheckboxPrimitive.Root.displayName + +export { Checkbox } diff --git a/components/ui/collapsible.tsx b/components/ui/collapsible.tsx new file mode 100644 index 0000000..9fa4894 --- /dev/null +++ b/components/ui/collapsible.tsx @@ -0,0 +1,11 @@ +"use client" + +import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" + +const Collapsible = CollapsiblePrimitive.Root + +const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger + +const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent + +export { Collapsible, CollapsibleTrigger, CollapsibleContent } diff --git a/components/ui/command.tsx b/components/ui/command.tsx new file mode 100644 index 0000000..2cecd91 --- /dev/null +++ b/components/ui/command.tsx @@ -0,0 +1,153 @@ +"use client" + +import * as React from "react" +import { type DialogProps } from "@radix-ui/react-dialog" +import { Command as CommandPrimitive } from "cmdk" +import { Search } from "lucide-react" + +import { cn } from "@/lib/utils" +import { Dialog, DialogContent } from "@/components/ui/dialog" + +const Command = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +Command.displayName = CommandPrimitive.displayName + +const CommandDialog = ({ children, ...props }: DialogProps) => { + return ( + + + + {children} + + + + ) +} + +const CommandInput = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( +
+ + +
+)) + +CommandInput.displayName = CommandPrimitive.Input.displayName + +const CommandList = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) + +CommandList.displayName = CommandPrimitive.List.displayName + +const CommandEmpty = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>((props, ref) => ( + +)) + +CommandEmpty.displayName = CommandPrimitive.Empty.displayName + +const CommandGroup = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) + +CommandGroup.displayName = CommandPrimitive.Group.displayName + +const CommandSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +CommandSeparator.displayName = CommandPrimitive.Separator.displayName + +const CommandItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) + +CommandItem.displayName = CommandPrimitive.Item.displayName + +const CommandShortcut = ({ + className, + ...props +}: React.HTMLAttributes) => { + return ( + + ) +} +CommandShortcut.displayName = "CommandShortcut" + +export { + Command, + CommandDialog, + CommandInput, + CommandList, + CommandEmpty, + CommandGroup, + CommandItem, + CommandShortcut, + CommandSeparator, +} diff --git a/components/ui/dialog.tsx b/components/ui/dialog.tsx new file mode 100644 index 0000000..1647513 --- /dev/null +++ b/components/ui/dialog.tsx @@ -0,0 +1,122 @@ +"use client" + +import * as React from "react" +import * as DialogPrimitive from "@radix-ui/react-dialog" +import { X } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Dialog = DialogPrimitive.Root + +const DialogTrigger = DialogPrimitive.Trigger + +const DialogPortal = DialogPrimitive.Portal + +const DialogClose = DialogPrimitive.Close + +const DialogOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName + +const DialogContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + {children} + + + Close + + + +)) +DialogContent.displayName = DialogPrimitive.Content.displayName + +const DialogHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +DialogHeader.displayName = "DialogHeader" + +const DialogFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +DialogFooter.displayName = "DialogFooter" + +const DialogTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogTitle.displayName = DialogPrimitive.Title.displayName + +const DialogDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogDescription.displayName = DialogPrimitive.Description.displayName + +export { + Dialog, + DialogPortal, + DialogOverlay, + DialogTrigger, + DialogClose, + DialogContent, + DialogHeader, + DialogFooter, + DialogTitle, + DialogDescription, +} diff --git a/components/ui/input.tsx b/components/ui/input.tsx new file mode 100644 index 0000000..69b64fb --- /dev/null +++ b/components/ui/input.tsx @@ -0,0 +1,22 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +const Input = React.forwardRef>( + ({ className, type, ...props }, ref) => { + return ( + + ) + } +) +Input.displayName = "Input" + +export { Input } diff --git a/components/ui/label.tsx b/components/ui/label.tsx new file mode 100644 index 0000000..5341821 --- /dev/null +++ b/components/ui/label.tsx @@ -0,0 +1,26 @@ +"use client" + +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const labelVariants = cva( + "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" +) + +const Label = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & + VariantProps +>(({ className, ...props }, ref) => ( + +)) +Label.displayName = LabelPrimitive.Root.displayName + +export { Label } diff --git a/components/ui/popover.tsx b/components/ui/popover.tsx new file mode 100644 index 0000000..70a28f6 --- /dev/null +++ b/components/ui/popover.tsx @@ -0,0 +1,33 @@ +"use client" + +import * as React from "react" +import * as PopoverPrimitive from "@radix-ui/react-popover" + +import { cn } from "@/lib/utils" + +const Popover = PopoverPrimitive.Root + +const PopoverTrigger = PopoverPrimitive.Trigger + +const PopoverAnchor = PopoverPrimitive.Anchor + +const PopoverContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( + + + +)) +PopoverContent.displayName = PopoverPrimitive.Content.displayName + +export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } diff --git a/components/ui/radio-group.tsx b/components/ui/radio-group.tsx new file mode 100644 index 0000000..0bdf685 --- /dev/null +++ b/components/ui/radio-group.tsx @@ -0,0 +1,44 @@ +"use client" + +import * as React from "react" +import * as RadioGroupPrimitive from "@radix-ui/react-radio-group" +import { Circle } from "lucide-react" + +import { cn } from "@/lib/utils" + +const RadioGroup = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + return ( + + ) +}) +RadioGroup.displayName = RadioGroupPrimitive.Root.displayName + +const RadioGroupItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + return ( + + + + + + ) +}) +RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName + +export { RadioGroup, RadioGroupItem } diff --git a/components/ui/select.tsx b/components/ui/select.tsx new file mode 100644 index 0000000..6e637f7 --- /dev/null +++ b/components/ui/select.tsx @@ -0,0 +1,159 @@ +"use client" + +import * as React from "react" +import * as SelectPrimitive from "@radix-ui/react-select" +import { Check, ChevronDown, ChevronUp } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Select = SelectPrimitive.Root + +const SelectGroup = SelectPrimitive.Group + +const SelectValue = SelectPrimitive.Value + +const SelectTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + span]:line-clamp-1", + className + )} + {...props} + > + {children} + + + + +)) +SelectTrigger.displayName = SelectPrimitive.Trigger.displayName + +const SelectScrollUpButton = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName + +const SelectScrollDownButton = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +SelectScrollDownButton.displayName = + SelectPrimitive.ScrollDownButton.displayName + +const SelectContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, position = "popper", ...props }, ref) => ( + + + + + {children} + + + + +)) +SelectContent.displayName = SelectPrimitive.Content.displayName + +const SelectLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SelectLabel.displayName = SelectPrimitive.Label.displayName + +const SelectItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + + + + {children} + +)) +SelectItem.displayName = SelectPrimitive.Item.displayName + +const SelectSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SelectSeparator.displayName = SelectPrimitive.Separator.displayName + +export { + Select, + SelectGroup, + SelectValue, + SelectTrigger, + SelectContent, + SelectLabel, + SelectItem, + SelectSeparator, + SelectScrollUpButton, + SelectScrollDownButton, +} diff --git a/components/ui/separator.tsx b/components/ui/separator.tsx new file mode 100644 index 0000000..12d81c4 --- /dev/null +++ b/components/ui/separator.tsx @@ -0,0 +1,31 @@ +"use client" + +import * as React from "react" +import * as SeparatorPrimitive from "@radix-ui/react-separator" + +import { cn } from "@/lib/utils" + +const Separator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>( + ( + { className, orientation = "horizontal", decorative = true, ...props }, + ref + ) => ( + + ) +) +Separator.displayName = SeparatorPrimitive.Root.displayName + +export { Separator } diff --git a/components/ui/sheet.tsx b/components/ui/sheet.tsx new file mode 100644 index 0000000..272cb72 --- /dev/null +++ b/components/ui/sheet.tsx @@ -0,0 +1,140 @@ +"use client" + +import * as React from "react" +import * as SheetPrimitive from "@radix-ui/react-dialog" +import { cva, type VariantProps } from "class-variance-authority" +import { X } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Sheet = SheetPrimitive.Root + +const SheetTrigger = SheetPrimitive.Trigger + +const SheetClose = SheetPrimitive.Close + +const SheetPortal = SheetPrimitive.Portal + +const SheetOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SheetOverlay.displayName = SheetPrimitive.Overlay.displayName + +const sheetVariants = cva( + "fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out", + { + variants: { + side: { + top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top", + bottom: + "inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom", + left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm", + right: + "inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm", + }, + }, + defaultVariants: { + side: "right", + }, + } +) + +interface SheetContentProps + extends React.ComponentPropsWithoutRef, + VariantProps {} + +const SheetContent = React.forwardRef< + React.ElementRef, + SheetContentProps +>(({ side = "right", className, children, ...props }, ref) => ( + + + + + + Close + + {children} + + +)) +SheetContent.displayName = SheetPrimitive.Content.displayName + +const SheetHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +SheetHeader.displayName = "SheetHeader" + +const SheetFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +SheetFooter.displayName = "SheetFooter" + +const SheetTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SheetTitle.displayName = SheetPrimitive.Title.displayName + +const SheetDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SheetDescription.displayName = SheetPrimitive.Description.displayName + +export { + Sheet, + SheetPortal, + SheetOverlay, + SheetTrigger, + SheetClose, + SheetContent, + SheetHeader, + SheetFooter, + SheetTitle, + SheetDescription, +} diff --git a/components/ui/sidebar.tsx b/components/ui/sidebar.tsx new file mode 100644 index 0000000..3ef110e --- /dev/null +++ b/components/ui/sidebar.tsx @@ -0,0 +1,773 @@ +"use client" + +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { VariantProps, cva } from "class-variance-authority" +import { PanelLeft } from "lucide-react" + +import { useIsMobile } from "@/hooks/use-mobile" +import { cn } from "@/lib/utils" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Separator } from "@/components/ui/separator" +import { + Sheet, + SheetContent, + SheetDescription, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { Skeleton } from "@/components/ui/skeleton" +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip" + +const SIDEBAR_COOKIE_NAME = "sidebar_state" +const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7 +const SIDEBAR_WIDTH = "17rem" +const SIDEBAR_WIDTH_MOBILE = "18rem" +const SIDEBAR_WIDTH_ICON = "3rem" +const SIDEBAR_KEYBOARD_SHORTCUT = "b" + +type SidebarContextProps = { + state: "expanded" | "collapsed" + open: boolean + setOpen: (open: boolean) => void + openMobile: boolean + setOpenMobile: (open: boolean) => void + isMobile: boolean + toggleSidebar: () => void +} + +const SidebarContext = React.createContext(null) + +function useSidebar() { + const context = React.useContext(SidebarContext) + if (!context) { + throw new Error("useSidebar must be used within a SidebarProvider.") + } + + return context +} + +const SidebarProvider = React.forwardRef< + HTMLDivElement, + React.ComponentProps<"div"> & { + defaultOpen?: boolean + open?: boolean + onOpenChange?: (open: boolean) => void + } +>( + ( + { + defaultOpen = true, + open: openProp, + onOpenChange: setOpenProp, + className, + style, + children, + ...props + }, + ref + ) => { + const isMobile = useIsMobile() + const [openMobile, setOpenMobile] = React.useState(false) + + // This is the internal state of the sidebar. + // We use openProp and setOpenProp for control from outside the component. + const [_open, _setOpen] = React.useState(defaultOpen) + const open = openProp ?? _open + const setOpen = React.useCallback( + (value: boolean | ((value: boolean) => boolean)) => { + const openState = typeof value === "function" ? value(open) : value + if (setOpenProp) { + setOpenProp(openState) + } else { + _setOpen(openState) + } + + // This sets the cookie to keep the sidebar state. + document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}` + }, + [setOpenProp, open] + ) + + // Helper to toggle the sidebar. + const toggleSidebar = React.useCallback(() => { + return isMobile + ? setOpenMobile((open) => !open) + : setOpen((open) => !open) + }, [isMobile, setOpen, setOpenMobile]) + + // Adds a keyboard shortcut to toggle the sidebar. + React.useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if ( + event.key === SIDEBAR_KEYBOARD_SHORTCUT && + (event.metaKey || event.ctrlKey) + ) { + event.preventDefault() + toggleSidebar() + } + } + + window.addEventListener("keydown", handleKeyDown) + return () => window.removeEventListener("keydown", handleKeyDown) + }, [toggleSidebar]) + + // We add a state so that we can do data-state="expanded" or "collapsed". + // This makes it easier to style the sidebar with Tailwind classes. + const state = open ? "expanded" : "collapsed" + + const contextValue = React.useMemo( + () => ({ + state, + open, + setOpen, + isMobile, + openMobile, + setOpenMobile, + toggleSidebar, + }), + [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar] + ) + + return ( + + +
+ {children} +
+
+
+ ) + } +) +SidebarProvider.displayName = "SidebarProvider" + +const Sidebar = React.forwardRef< + HTMLDivElement, + React.ComponentProps<"div"> & { + side?: "left" | "right" + variant?: "sidebar" | "floating" | "inset" + collapsible?: "offcanvas" | "icon" | "none" + } +>( + ( + { + side = "left", + variant = "sidebar", + collapsible = "offcanvas", + className, + children, + ...props + }, + ref + ) => { + const { isMobile, state, openMobile, setOpenMobile } = useSidebar() + + if (collapsible === "none") { + return ( +
+ {children} +
+ ) + } + + if (isMobile) { + return ( + + + + Sidebar + Displays the mobile sidebar. + +
{children}
+
+
+ ) + } + + return ( +
+ {/* This is what handles the sidebar gap on desktop */} +
+ +
+ ) + } +) +Sidebar.displayName = "Sidebar" + +const SidebarTrigger = React.forwardRef< + React.ElementRef, + React.ComponentProps +>(({ className, onClick, ...props }, ref) => { + const { toggleSidebar } = useSidebar() + + return ( + + ) +}) +SidebarTrigger.displayName = "SidebarTrigger" + +const SidebarRail = React.forwardRef< + HTMLButtonElement, + React.ComponentProps<"button"> +>(({ className, ...props }, ref) => { + const { toggleSidebar } = useSidebar() + + return ( +