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 0000000..718d6fe Binary files /dev/null and b/app/favicon.ico differ 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 ( +