first commit
59
.gitignore
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
db/
|
||||
start.sh
|
||||
supabase.sh
|
||||
|
||||
**/certificates/
|
||||
**/node_modules/
|
||||
**/dist/
|
||||
**/.next/
|
||||
**/.vercel/
|
||||
**/.DS_Store
|
||||
**/.env*
|
||||
# **/.npmrc
|
||||
|
||||
**/test.nnb
|
||||
server/test.nnb
|
||||
server/src/test.nnb
|
||||
|
||||
|
||||
pull.sh
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
3
.npmrc
Normal file
@@ -0,0 +1,3 @@
|
||||
@fortawesome:registry=https://npm.fontawesome.com/
|
||||
@awesome.me:registry=https://npm.fontawesome.com/
|
||||
//npm.fontawesome.com/:_authToken=${FONTAWESOME_PACKAGE_TOKEN}
|
||||
0
LICENSE.MD
Normal file
8
frontend/.eslintrc.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": ["next/core-web-vitals", "next/typescript"],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-unused-vars": "off",
|
||||
"@react-hooks/rules-of-hooks": "off"
|
||||
}
|
||||
}
|
||||
36
frontend/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
4
frontend/commit.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
git add .
|
||||
git commit -m "$1"
|
||||
git push
|
||||
|
||||
21
frontend/components.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "new-york",
|
||||
"rsc": true,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "tailwind.config.ts",
|
||||
"css": "src/app/globals.css",
|
||||
"baseColor": "zinc",
|
||||
"cssVariables": false,
|
||||
"prefix": ""
|
||||
},
|
||||
"aliases": {
|
||||
"components": "@/components",
|
||||
"utils": "@/lib/utils",
|
||||
"ui": "@/components/ui",
|
||||
"lib": "@/lib",
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"iconLibrary": "lucide"
|
||||
}
|
||||
8
frontend/next.config.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
reactStrictMode: false,
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
69
frontend/package.json
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "@autumn/frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@autumn/shared": "*",
|
||||
"@clerk/nextjs": "^6.9.14",
|
||||
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
||||
"@fortawesome/free-brands-svg-icons": "^6.7.2",
|
||||
"@fortawesome/pro-duotone-svg-icons": "^6.7.2",
|
||||
"@fortawesome/pro-regular-svg-icons": "^6.7.2",
|
||||
"@fortawesome/pro-solid-svg-icons": "^6.7.2",
|
||||
"@fortawesome/react-fontawesome": "^0.2.2",
|
||||
"@nextui-org/react": "^2.6.3",
|
||||
"@nextui-org/spinner": "^2.0.34",
|
||||
"@nextui-org/system": "^2.2.6",
|
||||
"@nextui-org/theme": "^2.2.11",
|
||||
"@radix-ui/react-accordion": "^1.2.1",
|
||||
"@radix-ui/react-checkbox": "^1.1.3",
|
||||
"@radix-ui/react-dialog": "^1.1.4",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.2",
|
||||
"@radix-ui/react-popover": "^1.1.4",
|
||||
"@radix-ui/react-select": "^2.1.4",
|
||||
"@radix-ui/react-separator": "^1.1.0",
|
||||
"@radix-ui/react-slot": "^1.1.0",
|
||||
"@radix-ui/react-switch": "^1.1.2",
|
||||
"@radix-ui/react-tabs": "^1.1.2",
|
||||
"@radix-ui/react-toast": "^1.2.2",
|
||||
"@radix-ui/react-tooltip": "^1.1.4",
|
||||
"@supabase/ssr": "^0.5.2",
|
||||
"@supabase/supabase-js": "^2.47.2",
|
||||
"@wooorm/starry-night": "^3.5.0",
|
||||
"axios": "^1.7.9",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.0.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"framer-motion": "^11.13.1",
|
||||
"hast-util-to-html": "^8.0.0",
|
||||
"lucide-react": "^0.468.0",
|
||||
"next": "15.0.3",
|
||||
"ora": "^8.1.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-hot-toast": "^2.4.1",
|
||||
"react-hotkeys-hook": "^4.6.1",
|
||||
"swr": "^2.2.5",
|
||||
"tailwind-merge": "^2.5.5",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"vaul": "^1.1.1",
|
||||
"zod": "^3.24.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "15.0.3",
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.4.16",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
8
frontend/postcss.config.mjs
Normal file
@@ -0,0 +1,8 @@
|
||||
/** @type {import('postcss-load-config').Config} */
|
||||
const config = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
1
frontend/public/file.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
frontend/public/globe.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
4
frontend/public/logo.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="3646" height="3646" viewBox="0 0 3646 3646" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="1645.5" cy="1637.5" r="1377.5" stroke="#7839FF" stroke-width="80"/>
|
||||
<circle cx="1922.5" cy="1932.5" r="1267.5" stroke="#4D00F3" stroke-opacity="0.95" stroke-width="300"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 294 B |
1
frontend/public/next.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
frontend/public/vercel.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
1
frontend/public/window.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
13
frontend/src/app/credits/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import CreditSystemsView from "@/views/credits/CreditSystemsView";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
|
||||
async function CreditPage() {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
|
||||
return <CreditSystemsView env={env} />;
|
||||
}
|
||||
|
||||
export default CreditPage;
|
||||
@@ -0,0 +1,27 @@
|
||||
import CustomerProductView from "@/views/customers/customer/product/CustomerProductView";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
import { getOrgFromSession } from "@/utils/serverUtils";
|
||||
|
||||
async function CustomerProductPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ product_id: string; customer_id: string }>;
|
||||
}) {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
const org = await getOrgFromSession();
|
||||
const { product_id, customer_id } = await params;
|
||||
|
||||
return (
|
||||
<CustomerProductView
|
||||
product_id={product_id}
|
||||
customer_id={customer_id}
|
||||
env={env}
|
||||
org={org}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default CustomerProductPage;
|
||||
16
frontend/src/app/customers/[customer_id]/page.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import CustomerView from "@/views/customers/customer/CustomerView";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
|
||||
export default async function CustomerPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ customer_id: string }>;
|
||||
}) {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
const { customer_id } = await params;
|
||||
|
||||
return <CustomerView customer_id={customer_id} env={env} />;
|
||||
}
|
||||
13
frontend/src/app/customers/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
|
||||
import CustomersView from "@/views/customers/CustomersView";
|
||||
|
||||
async function CustomersPage() {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
return <CustomersView env={env} />;
|
||||
}
|
||||
|
||||
export default CustomersPage;
|
||||
5
frontend/src/app/demo/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import DemoView from "@/views/demo/DemoView";
|
||||
|
||||
export default function DemoPage() {
|
||||
return <DemoView />;
|
||||
}
|
||||
13
frontend/src/app/dev/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
import DevView from "@/views/developer/DevView";
|
||||
|
||||
async function DevPage() {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
|
||||
return <DevView env={env} />;
|
||||
}
|
||||
|
||||
export default DevPage;
|
||||
BIN
frontend/src/app/favicon.ico
Normal file
|
After Width: | Height: | Size: 174 KiB |
13
frontend/src/app/features/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import FeaturesView from "@/views/features/FeaturesView";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
|
||||
async function FeaturesPage() {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
|
||||
return <FeaturesView env={env} />;
|
||||
}
|
||||
|
||||
export default FeaturesPage;
|
||||
BIN
frontend/src/app/fonts/GeistMonoVF.woff
Normal file
BIN
frontend/src/app/fonts/GeistVF.woff
Normal file
32
frontend/src/app/globals.css
Normal file
@@ -0,0 +1,32 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
body {
|
||||
/* font-family: Arial, Helvetica, sans-serif; */
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--radius: 0.5rem;
|
||||
--sidebar-background: 0 0% 98%;
|
||||
--sidebar-foreground: 240 5.3% 26.1%;
|
||||
--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 {
|
||||
--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%;
|
||||
}
|
||||
}
|
||||
0
frontend/src/app/integrations/callback.ts
Normal file
10
frontend/src/app/integrations/stripe/page.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { getOrgFromSession } from "@/utils/serverUtils";
|
||||
import ConnectStripe from "@/views/onboarding/ConnectStripe";
|
||||
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
export default async function StripePage() {
|
||||
const org = await getOrgFromSession();
|
||||
|
||||
return <ConnectStripe org={org} />;
|
||||
}
|
||||
119
frontend/src/app/layout.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
import "./globals.css";
|
||||
import { ClerkProvider } from "@clerk/nextjs";
|
||||
import { NextUIProvider } from "@nextui-org/react";
|
||||
import { Inter } from "next/font/google";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
import { config } from "@fortawesome/fontawesome-svg-core";
|
||||
import "@fortawesome/fontawesome-svg-core/styles.css";
|
||||
config.autoAddCss = false;
|
||||
|
||||
const getTitle = async () => {
|
||||
// const headersList = await headers();
|
||||
// const origin = headersList.get("origin");
|
||||
|
||||
// if (origin === "https://app.autumn.com") {
|
||||
// return "Autumn";
|
||||
// } else {
|
||||
// return "Autumn (Local)";
|
||||
// }
|
||||
return "Autumn";
|
||||
};
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: await getTitle(),
|
||||
description:
|
||||
"Handling pricing plans, packaging and entitlements for your customers",
|
||||
};
|
||||
|
||||
import React from "react";
|
||||
|
||||
import { auth } from "@clerk/nextjs/server";
|
||||
import { headers } from "next/headers";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { redirect } from "next/navigation";
|
||||
import { SidebarProvider } from "../components/ui/sidebar";
|
||||
import HomeSidebar from "../views/sidebar/Sidebar";
|
||||
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
const path = headersList.get("path") || "";
|
||||
|
||||
const { sessionClaims }: { sessionClaims: any } = await auth();
|
||||
const { org_id, org } = sessionClaims || {};
|
||||
|
||||
if (path.includes("/onboarding")) {
|
||||
if (org_id) {
|
||||
redirect("/sandbox/customers");
|
||||
}
|
||||
|
||||
return (
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<body
|
||||
className={`${inter.className} font-regular`}
|
||||
suppressHydrationWarning
|
||||
>
|
||||
{/* @ts-expect-error ClerkProvider is not a valid JSX component */}
|
||||
<ClerkProvider>
|
||||
<NextUIProvider>
|
||||
<main className="w-full h-screen overflow-hidden">
|
||||
{children}
|
||||
</main>
|
||||
</NextUIProvider>
|
||||
</ClerkProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
// Main layout
|
||||
// const user = await currentUser();
|
||||
|
||||
if (!org_id) {
|
||||
redirect("/onboarding");
|
||||
}
|
||||
|
||||
return (
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<body
|
||||
className={`${inter.className} font-regular`}
|
||||
suppressHydrationWarning
|
||||
>
|
||||
{/* @ts-expect-error ClerkProvider is not a valid JSX component */}
|
||||
<ClerkProvider>
|
||||
<NextUIProvider>
|
||||
<SidebarProvider>
|
||||
<HomeSidebar
|
||||
user={sessionClaims?.user as any}
|
||||
org={org}
|
||||
path={path}
|
||||
env={env as AppEnv}
|
||||
/>
|
||||
<main className="flex flex-col w-full h-screen overflow-hidden">
|
||||
{env === AppEnv.Sandbox && (
|
||||
<div className="w-full h-5 bg-primary/80 text-white text-xs flex items-center justify-center">
|
||||
<p className="font-medium">SANDBOX</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="w-full h-screen overflow-hidden bg-stone-50 p-6 flex justify-center">
|
||||
<div className="w-full max-w-[1048px] flex flex-col gap-4">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</SidebarProvider>
|
||||
</NextUIProvider>
|
||||
</ClerkProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
6
frontend/src/app/loading.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import LoadingScreen from "@/views/general/LoadingScreen";
|
||||
|
||||
export default function Loading() {
|
||||
// You can add any UI inside Loading, including a Skeleton.
|
||||
return <LoadingScreen />;
|
||||
}
|
||||
8
frontend/src/app/onboarding/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import OnboardingView from "@/views/onboarding/OnboardingView";
|
||||
|
||||
async function OnboardingPage() {
|
||||
const onboardingView = await OnboardingView();
|
||||
return onboardingView;
|
||||
}
|
||||
|
||||
export default OnboardingPage;
|
||||
22
frontend/src/app/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import HomeView from "@/views/HomeView";
|
||||
import HomeSidebar from "@/views/sidebar/Sidebar";
|
||||
import { currentUser } from "@clerk/nextjs/server";
|
||||
import { headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
enum AppEnv {
|
||||
Sandbox = "sandbox",
|
||||
}
|
||||
|
||||
async function Home() {
|
||||
redirect("/customers");
|
||||
// const org = await currentOrganization();
|
||||
|
||||
return (
|
||||
<div className="w-full h-full">{/* <HomeView /> */}</div>
|
||||
// <SidebarProvider>
|
||||
// </SidebarProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default Home;
|
||||
21
frontend/src/app/products/[product_id]/page.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import ProductView from "@/views/products/product/ProductView";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
import { Organization, AppEnv } from "@autumn/shared";
|
||||
import { getOrgFromSession } from "@/utils/serverUtils";
|
||||
|
||||
async function ProductPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ product_id: string }>;
|
||||
}) {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
const { product_id } = await params;
|
||||
|
||||
const org: Organization = await getOrgFromSession();
|
||||
|
||||
return <ProductView product_id={product_id} env={env} org={org} />;
|
||||
}
|
||||
|
||||
export default ProductPage;
|
||||
14
frontend/src/app/products/page.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
import { headers } from "next/headers";
|
||||
import React from "react";
|
||||
import ProductsView from "@/views/products/ProductsView";
|
||||
import { auth } from "@clerk/nextjs/server";
|
||||
|
||||
async function ProductsPage() {
|
||||
const headersList = await headers();
|
||||
const env = (headersList.get("env") as AppEnv) || AppEnv.Sandbox;
|
||||
|
||||
return <ProductsView env={env} />;
|
||||
}
|
||||
|
||||
export default ProductsPage;
|
||||
41
frontend/src/components/general/CopyButton.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Button, ButtonProps } from "../ui/button";
|
||||
import { Check, Copy } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function CopyButton({
|
||||
text,
|
||||
className,
|
||||
children,
|
||||
variant = "ghost",
|
||||
}: {
|
||||
text: string;
|
||||
className?: string;
|
||||
children?: React.ReactNode;
|
||||
variant?: string;
|
||||
}) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 1000);
|
||||
}, [copied]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant={variant as ButtonProps["variant"]}
|
||||
size="icon"
|
||||
className={cn("h-6 w-6 p-0.5", className)}
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(text);
|
||||
setCopied(true);
|
||||
}}
|
||||
>
|
||||
<p>{children}</p>
|
||||
{copied ? <Check size={13} /> : <Copy size={13} />}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default CopyButton;
|
||||
13
frontend/src/components/general/CustomToaster.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
export const CustomToaster = () => {
|
||||
return (
|
||||
<Toaster
|
||||
position="bottom-center"
|
||||
toastOptions={{
|
||||
duration: 2000,
|
||||
style: { fontSize: "14px" },
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
8
frontend/src/components/general/SmallSpinner.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Spinner } from "@nextui-org/spinner";
|
||||
import React from "react";
|
||||
|
||||
function SmallSpinner() {
|
||||
return <Spinner color="default" size="sm" className="scale-80" />;
|
||||
}
|
||||
|
||||
export default SmallSpinner;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
import React from "react";
|
||||
|
||||
function FieldLabel({ children, className }: any) {
|
||||
return (
|
||||
<div className={cn("text-t3 text-sm mb-2", className)}>{children}</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FieldLabel;
|
||||
57
frontend/src/components/ui/accordion.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||
import { ChevronDown } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Accordion = AccordionPrimitive.Root
|
||||
|
||||
const AccordionItem = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AccordionPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn("border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AccordionItem.displayName = "AccordionItem"
|
||||
|
||||
const AccordionTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDown className="h-4 w-4 shrink-0 text-zinc-500 transition-transform duration-200 dark:text-zinc-400" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
))
|
||||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
||||
|
||||
const AccordionContent = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Content
|
||||
ref={ref}
|
||||
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
))
|
||||
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
||||
59
frontend/src/components/ui/alert.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const alertVariants = cva(
|
||||
"relative w-full rounded-lg border border-zinc-200 px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-zinc-950 [&>svg~*]:pl-7 dark:border-zinc-800 dark:[&>svg]:text-zinc-50",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-white text-zinc-950 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
destructive:
|
||||
"border-red-500/50 text-red-500 dark:border-red-500 [&>svg]:text-red-500 dark:border-red-900/50 dark:text-red-900 dark:dark:border-red-900 dark:[&>svg]:text-red-900",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const Alert = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
|
||||
>(({ className, variant, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
role="alert"
|
||||
className={cn(alertVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Alert.displayName = "Alert"
|
||||
|
||||
const AlertTitle = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<h5
|
||||
ref={ref}
|
||||
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AlertTitle.displayName = "AlertTitle"
|
||||
|
||||
const AlertDescription = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("text-sm [&_p]:leading-relaxed", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AlertDescription.displayName = "AlertDescription"
|
||||
|
||||
export { Alert, AlertTitle, AlertDescription }
|
||||
38
frontend/src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center rounded-full border border-zinc-200 px-2.5 py-0.5 text-xs transition-colors focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 dark:border-zinc-800 dark:focus:ring-zinc-300",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-zinc-900 text-zinc-50 shadow hover:bg-zinc-900/80 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-50/80",
|
||||
secondary:
|
||||
"border-transparent bg-zinc-100 text-zinc-900 hover:bg-zinc-100/80 dark:bg-zinc-800 dark:text-zinc-50 dark:hover:bg-zinc-800/80",
|
||||
destructive:
|
||||
"border-transparent bg-red-500 text-zinc-50 shadow hover:bg-red-500/80 dark:bg-red-900 dark:text-zinc-50 dark:hover:bg-red-900/80",
|
||||
outline: "text-zinc-950 dark:text-zinc-50",
|
||||
purple: "bg-purple-50 text-purple-500",
|
||||
blue: "bg-blue-50 text-blue-500",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
export interface BadgeProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
|
||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||
return (
|
||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
107
frontend/src/components/ui/button.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
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";
|
||||
import { LoaderCircle } from "lucide-react";
|
||||
|
||||
// [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0
|
||||
|
||||
const buttonVariants = cva(
|
||||
`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-zinc-300 font-regular
|
||||
|
||||
`,
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
// "bg-zinc-900 text-zinc-50 shadow hover:bg-zinc-900/90 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-50/90",
|
||||
"bg-primary hover:bg-primary/90 text-zinc-50 shadow dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-50/90",
|
||||
secondary:
|
||||
"border border-zinc-200 bg-white shadow-sm hover:bg-zinc-100 hover:text-zinc-900 dark:border-zinc-800 dark:bg-zinc-950 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",
|
||||
// "bg-zinc-100 text-zinc-900 shadow-sm hover:bg-zinc-100/80 dark:bg-zinc-800 dark:text-zinc-50 dark:hover:bg-zinc-800/80",
|
||||
destructive:
|
||||
"bg-red-500 text-zinc-50 shadow-sm hover:bg-red-500/90 dark:bg-red-900 dark:text-zinc-50 dark:hover:bg-red-900/90",
|
||||
outline:
|
||||
"border border-zinc-200 bg-white shadow-sm hover:bg-zinc-100 hover:text-zinc-900 dark:border-zinc-800 dark:bg-zinc-950 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",
|
||||
ghost:
|
||||
"hover:bg-zinc-100 hover:text-zinc-900 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",
|
||||
link: "text-zinc-900 underline-offset-4 hover:underline dark:text-zinc-50",
|
||||
dashed:
|
||||
"border border-1 border-dashed bg-white border-zinc-300 text-primary shadow-sm hover:bg-zinc-100 hover:text-primary dark:border-zinc-800 dark:bg-zinc-950 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",
|
||||
gradientPrimary:
|
||||
" bg-gradient-to-b from-primary/65 to-primary text-white hover:from-purple-500 hover:to-purple-700 shadow-sm text-xs shadow-purple-500/50",
|
||||
gradientSecondary:
|
||||
"border border-stone-300 bg-gradient-to-b from-white to-stone-100 text-t1 hover:from-stone-300 hover:to-stone-400 shadow-sm text-xs",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 px-3 flex items-center gap-1",
|
||||
sm: "h-7 rounded-md px-2 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<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
isLoading?: boolean;
|
||||
isIcon?: boolean;
|
||||
dim?: number;
|
||||
startIcon?: React.ReactNode;
|
||||
endIcon?: React.ReactNode;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
asChild = false,
|
||||
isLoading = false,
|
||||
isIcon = false,
|
||||
dim = 7,
|
||||
startIcon,
|
||||
endIcon,
|
||||
children,
|
||||
...props
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (
|
||||
<Comp
|
||||
{...props}
|
||||
className={cn(
|
||||
buttonVariants({ variant, size, className }),
|
||||
isIcon && `w-${dim} h-${dim}`
|
||||
)}
|
||||
ref={ref}
|
||||
onClick={(e) => {
|
||||
if (isLoading) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
props.onClick?.(e);
|
||||
}}
|
||||
>
|
||||
{isLoading && <LoaderCircle className="animate-spin" size={20} />}
|
||||
{startIcon && !isLoading && <>{startIcon}</>}
|
||||
{children}
|
||||
{endIcon && !isLoading && <>{endIcon}</>}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
76
frontend/src/components/ui/card.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Card = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"rounded-xl border border-zinc-200 bg-white text-zinc-950 shadow dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Card.displayName = "Card"
|
||||
|
||||
const CardHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardHeader.displayName = "CardHeader"
|
||||
|
||||
const CardTitle = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardTitle.displayName = "CardTitle"
|
||||
|
||||
const CardDescription = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("text-sm text-zinc-500 dark:text-zinc-400", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardDescription.displayName = "CardDescription"
|
||||
|
||||
const CardContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||
))
|
||||
CardContent.displayName = "CardContent"
|
||||
|
||||
const CardFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex items-center p-6 pt-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardFooter.displayName = "CardFooter"
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|
||||
30
frontend/src/components/ui/checkbox.tsx
Normal file
@@ -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<typeof CheckboxPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CheckboxPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"peer h-4 w-4 shrink-0 rounded-sm border border-zinc-200 border-zinc-900 shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-zinc-900 data-[state=checked]:text-zinc-50 dark:border-zinc-800 dark:border-zinc-50 dark:focus-visible:ring-zinc-300 dark:data-[state=checked]:bg-zinc-50 dark:data-[state=checked]:text-zinc-900",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
className={cn("flex items-center justify-center text-current")}
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
))
|
||||
Checkbox.displayName = CheckboxPrimitive.Root.displayName
|
||||
|
||||
export { Checkbox }
|
||||
153
frontend/src/components/ui/command.tsx
Normal file
@@ -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<typeof CommandPrimitive>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-full w-full flex-col overflow-hidden rounded-md bg-white text-zinc-950 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Command.displayName = CommandPrimitive.displayName
|
||||
|
||||
const CommandDialog = ({ children, ...props }: DialogProps) => {
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogContent className="overflow-hidden p-0">
|
||||
<Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-zinc-500 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5 dark:[&_[cmdk-group-heading]]:text-zinc-400">
|
||||
{children}
|
||||
</Command>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
const CommandInput = React.forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Input>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
|
||||
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
<CommandPrimitive.Input
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:placeholder:text-zinc-400",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
|
||||
CommandInput.displayName = CommandPrimitive.Input.displayName
|
||||
|
||||
const CommandList = React.forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.List
|
||||
ref={ref}
|
||||
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
|
||||
CommandList.displayName = CommandPrimitive.List.displayName
|
||||
|
||||
const CommandEmpty = React.forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Empty>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
||||
>((props, ref) => (
|
||||
<CommandPrimitive.Empty
|
||||
ref={ref}
|
||||
className="py-6 text-center text-sm"
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
|
||||
CommandEmpty.displayName = CommandPrimitive.Empty.displayName
|
||||
|
||||
const CommandGroup = React.forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Group>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.Group
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"overflow-hidden p-1 text-zinc-950 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-zinc-500 dark:text-zinc-50 dark:[&_[cmdk-group-heading]]:text-zinc-400",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
|
||||
CommandGroup.displayName = CommandPrimitive.Group.displayName
|
||||
|
||||
const CommandSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 h-px bg-zinc-200 dark:bg-zinc-800", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CommandSeparator.displayName = CommandPrimitive.Separator.displayName
|
||||
|
||||
const CommandItem = React.forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-zinc-100 data-[selected=true]:text-zinc-900 data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:data-[selected=true]:bg-zinc-800 dark:data-[selected=true]:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
|
||||
CommandItem.displayName = CommandPrimitive.Item.displayName
|
||||
|
||||
const CommandShortcut = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"ml-auto text-xs tracking-widest text-zinc-500 dark:text-zinc-400",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
CommandShortcut.displayName = "CommandShortcut"
|
||||
|
||||
export {
|
||||
Command,
|
||||
CommandDialog,
|
||||
CommandInput,
|
||||
CommandList,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandItem,
|
||||
CommandShortcut,
|
||||
CommandSeparator,
|
||||
}
|
||||
123
frontend/src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,123 @@
|
||||
"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<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-white/70 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border-2 bg-stone-50 p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-zinc-800 dark:bg-zinc-950",
|
||||
"w-[500px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-zinc-100 data-[state=open]:text-zinc-500 dark:ring-offset-zinc-950 dark:focus:ring-zinc-300 dark:data-[state=open]:bg-zinc-800 dark:data-[state=open]:text-zinc-400">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
));
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
const DialogHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-1.5 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DialogHeader.displayName = "DialogHeader";
|
||||
|
||||
const DialogFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DialogFooter.displayName = "DialogFooter";
|
||||
|
||||
const DialogTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"text-lg font-semibold leading-none tracking-tight",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||
|
||||
const DialogDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-zinc-500 dark:text-zinc-400", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogPortal,
|
||||
DialogOverlay,
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogFooter,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
};
|
||||
97
frontend/src/components/ui/drawer.tsx
Normal file
@@ -0,0 +1,97 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { Drawer as DrawerPrimitive } from "vaul";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Drawer = ({
|
||||
shouldScaleBackground = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
|
||||
<DrawerPrimitive.Root
|
||||
shouldScaleBackground={shouldScaleBackground}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
Drawer.displayName = "Drawer";
|
||||
|
||||
const DrawerTrigger = DrawerPrimitive.Trigger;
|
||||
|
||||
const DrawerPortal = DrawerPrimitive.Portal;
|
||||
|
||||
const DrawerClose = DrawerPrimitive.Close;
|
||||
|
||||
const DrawerOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
||||
>(({ ...props }, ref) => <DrawerPrimitive.Overlay ref={ref} {...props} />);
|
||||
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
|
||||
|
||||
const DrawerContent = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DrawerPortal>
|
||||
<DrawerOverlay />
|
||||
<DrawerPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border border-zinc-200 bg-white dark:border-zinc-800 dark:bg-zinc-950",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-zinc-100 dark:bg-zinc-800" />
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
));
|
||||
DrawerContent.displayName = "DrawerContent";
|
||||
|
||||
const DrawerHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DrawerHeader.displayName = "DrawerHeader";
|
||||
|
||||
const DrawerFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DrawerFooter.displayName = "DrawerFooter";
|
||||
|
||||
const DrawerTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
||||
>(({ ...props }, ref) => <DrawerPrimitive.Title ref={ref} {...props} />);
|
||||
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
|
||||
|
||||
const DrawerDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
||||
>(({ ...props }, ref) => <DrawerPrimitive.Description ref={ref} {...props} />);
|
||||
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerPortal,
|
||||
DrawerOverlay,
|
||||
DrawerTrigger,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerHeader,
|
||||
DrawerFooter,
|
||||
DrawerTitle,
|
||||
DrawerDescription,
|
||||
};
|
||||
207
frontend/src/components/ui/dropdown-menu.tsx
Normal file
@@ -0,0 +1,207 @@
|
||||
"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<typeof DropdownMenuPrimitive.SubTrigger>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-zinc-100 data-[state=open]:bg-zinc-100 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus:bg-zinc-800 dark:data-[state=open]:bg-zinc-800",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRight className="ml-auto" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
));
|
||||
DropdownMenuSubTrigger.displayName =
|
||||
DropdownMenuPrimitive.SubTrigger.displayName;
|
||||
|
||||
const DropdownMenuSubContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border border-zinc-200 bg-white p-1 text-zinc-950 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuSubContent.displayName =
|
||||
DropdownMenuPrimitive.SubContent.displayName;
|
||||
|
||||
const DropdownMenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
onCloseAutoFocus={(e) => e.preventDefault()}
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border border-zinc-200 bg-white p-1 text-zinc-950 shadow-md dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
));
|
||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
||||
|
||||
const DropdownMenuItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-zinc-100 focus:text-zinc-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0 dark:focus:bg-zinc-800 dark:focus:text-zinc-50
|
||||
|
||||
|
||||
cursor-pointer
|
||||
hover:bg-zinc-100
|
||||
`,
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
||||
|
||||
const DropdownMenuCheckboxItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
||||
>(({ className, children, checked, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-zinc-100 focus:text-zinc-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-zinc-800 dark:focus:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
));
|
||||
DropdownMenuCheckboxItem.displayName =
|
||||
DropdownMenuPrimitive.CheckboxItem.displayName;
|
||||
|
||||
const DropdownMenuRadioItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-zinc-100 focus:text-zinc-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-zinc-800 dark:focus:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<Circle className="h-2 w-2 fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
));
|
||||
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
||||
|
||||
const DropdownMenuLabel = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-semibold",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
||||
|
||||
const DropdownMenuSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-zinc-100 dark:bg-zinc-800", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
||||
|
||||
const DropdownMenuShortcut = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
||||
return (
|
||||
<span
|
||||
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut";
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuRadioGroup,
|
||||
};
|
||||
92
frontend/src/components/ui/input.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface InputProps extends React.ComponentProps<"input"> {
|
||||
startContent?: React.ReactNode;
|
||||
endContent?: React.ReactNode;
|
||||
}
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, startContent, endContent, ...props }, ref) => {
|
||||
const hasAdornment = startContent || endContent;
|
||||
const [isFocused, setIsFocused] = React.useState(false);
|
||||
|
||||
const handleFocus = () => setIsFocused(true);
|
||||
const handleBlur = () => setIsFocused(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
{hasAdornment ? (
|
||||
<div
|
||||
className={cn(
|
||||
`flex w-full rounded-md border border-input bg-white text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50
|
||||
|
||||
h-8 transition-colors duration-100 shadow-sm
|
||||
`,
|
||||
isFocused &&
|
||||
`transition-colors duration-100 focus-visible:outline-none focus-visible:ring-0
|
||||
border-[rgb(139,92,246)] shadow-[0_0_2px_1px_rgba(139,92,246,0.25)]`,
|
||||
className
|
||||
)}
|
||||
data-disabled={props.disabled}
|
||||
>
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
`flex h-full w-full bg-white py-2 text-sm file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground shadow-none outline-none border-none focus-visible:outline-none focus-visible:border-none focus-visible:shadow-none
|
||||
[&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none
|
||||
|
||||
p-2
|
||||
`,
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
onFocus={handleFocus}
|
||||
onBlur={handleBlur}
|
||||
{...props}
|
||||
/>
|
||||
<div className="flex items-center justify-center pr-2">
|
||||
{endContent}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
`flex w-full rounded-md border border-zinc-200 bg-white px-3 py-1 text-base transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-zinc-950 placeholder:text-zinc-500 disabled:cursor-not-allowed disabled:opacity-50
|
||||
md:text-sm dark:border-zinc-800 dark:file:text-zinc-50 dark:placeholder:text-zinc-400
|
||||
|
||||
p-2 h-8 shadow-sm
|
||||
|
||||
transition-colors duration-100 focus-visible:outline-none focus-visible:ring-0
|
||||
focus-visible:border-[rgb(139,92,246)] focus-visible:shadow-[0_0_2px_1px_rgba(139,92,246,0.25)]`,
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
// return (
|
||||
// <input
|
||||
// type={type}
|
||||
// className={cn(
|
||||
// `flex w-full rounded-md border border-zinc-200 bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-zinc-950 placeholder:text-zinc-500 disabled:cursor-not-allowed disabled:opacity-50
|
||||
// md:text-sm dark:border-zinc-800 dark:file:text-zinc-50 dark:placeholder:text-zinc-400
|
||||
// p-2 h-8
|
||||
|
||||
// transition-colors duration-100 focus-visible:outline-none focus-visible:ring-0
|
||||
// focus-visible:border-[rgb(139,92,246)] focus-visible:shadow-[0_0_2px_1px_rgba(139,92,246,0.25)]`,
|
||||
// className
|
||||
// )}
|
||||
// ref={ref}
|
||||
// {...props}
|
||||
// />
|
||||
// );
|
||||
}
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
33
frontend/src/components/ui/popover.tsx
Normal file
@@ -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<typeof PopoverPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
||||
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Content
|
||||
ref={ref}
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 w-72 rounded-md border border-zinc-200 bg-white text-zinc-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
));
|
||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
||||
|
||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
||||
171
frontend/src/components/ui/select.tsx
Normal file
@@ -0,0 +1,171 @@
|
||||
"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;
|
||||
|
||||
// Default
|
||||
|
||||
// flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-zinc-200 bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-white placeholder:text-zinc-500 focus:outline-none focus:ring-1 focus:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 dark:border-zinc-800 dark:ring-offset-zinc-950 dark:placeholder:text-zinc-400 dark:focus:ring-zinc-300
|
||||
|
||||
const SelectTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
`flex w-full items-center justify-between whitespace-nowrap rounded-md border border-zinc-200 bg-white px-3 py-2 text-sm shadow-sm ring-offset-white placeholder:text-zinc-500 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 dark:border-zinc-800 dark:ring-offset-zinc-950 dark:placeholder:text-zinc-400 dark:focus:ring-zinc-300
|
||||
|
||||
h-8
|
||||
focus:ring-0 focus:border-[rgb(139,92,246)] focus:shadow-[0_0_2px_1px_rgba(139,92,246,0.25)]
|
||||
transition-colors duration-100
|
||||
|
||||
p-2
|
||||
`,
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDown className="h-4 w-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
));
|
||||
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
||||
|
||||
const SelectScrollUpButton = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUp className="h-4 w-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
));
|
||||
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
||||
|
||||
const SelectScrollDownButton = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
));
|
||||
SelectScrollDownButton.displayName =
|
||||
SelectPrimitive.ScrollDownButton.displayName;
|
||||
|
||||
const SelectContent = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||||
>(({ className, children, position = "popper", ...props }, ref) => (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-zinc-200 bg-white text-zinc-950 shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
));
|
||||
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
||||
|
||||
const SelectLabel = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
||||
|
||||
const SelectItem = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-zinc-100 focus:text-zinc-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-zinc-800 dark:focus:text-zinc-50",
|
||||
"hover:bg-zinc-100 cursor-pointer",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
));
|
||||
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
||||
|
||||
const SelectSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-zinc-100 dark:bg-zinc-800", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectGroup,
|
||||
SelectValue,
|
||||
SelectTrigger,
|
||||
SelectContent,
|
||||
SelectLabel,
|
||||
SelectItem,
|
||||
SelectSeparator,
|
||||
SelectScrollUpButton,
|
||||
SelectScrollDownButton,
|
||||
};
|
||||
31
frontend/src/components/ui/separator.tsx
Normal file
@@ -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<typeof SeparatorPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
||||
>(
|
||||
(
|
||||
{ className, orientation = "horizontal", decorative = true, ...props },
|
||||
ref
|
||||
) => (
|
||||
<SeparatorPrimitive.Root
|
||||
ref={ref}
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"shrink-0 bg-zinc-200 dark:bg-zinc-800",
|
||||
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
)
|
||||
Separator.displayName = SeparatorPrimitive.Root.displayName
|
||||
|
||||
export { Separator }
|
||||
144
frontend/src/components/ui/sheet.tsx
Normal file
@@ -0,0 +1,144 @@
|
||||
"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<typeof SheetPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Overlay
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
));
|
||||
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
|
||||
|
||||
const sheetVariants = cva(
|
||||
"fixed z-50 gap-4 bg-white 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 dark:bg-zinc-950",
|
||||
{
|
||||
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<typeof SheetPrimitive.Content>,
|
||||
VariantProps<typeof sheetVariants> {}
|
||||
|
||||
const SheetContent = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Content>,
|
||||
SheetContentProps
|
||||
// @ts-expect-error - className is inherited from ComponentPropsWithoutRef<typeof SheetPrimitive.Content>
|
||||
>(({ side = "right", className, children, ...props }, ref) => (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(sheetVariants({ side }), className)}
|
||||
{...props}
|
||||
>
|
||||
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-zinc-100 dark:ring-offset-zinc-950 dark:focus:ring-zinc-300 dark:data-[state=open]:bg-zinc-800">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
{children}
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
));
|
||||
SheetContent.displayName = SheetPrimitive.Content.displayName;
|
||||
|
||||
const SheetHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-2 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
SheetHeader.displayName = "SheetHeader";
|
||||
|
||||
const SheetFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
SheetFooter.displayName = "SheetFooter";
|
||||
|
||||
const SheetTitle = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"text-lg font-semibold text-zinc-950 dark:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SheetTitle.displayName = SheetPrimitive.Title.displayName;
|
||||
|
||||
const SheetDescription = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-zinc-500 dark:text-zinc-400", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SheetDescription.displayName = SheetPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetPortal,
|
||||
SheetOverlay,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
};
|
||||
764
frontend/src/components/ui/sidebar.tsx
Normal file
@@ -0,0 +1,764 @@
|
||||
"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 } 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 = "13rem";
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
||||
const SIDEBAR_WIDTH_ICON = "3rem";
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
||||
|
||||
type SidebarContext = {
|
||||
state: "expanded" | "collapsed";
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
openMobile: boolean;
|
||||
setOpenMobile: (open: boolean) => void;
|
||||
isMobile: boolean;
|
||||
toggleSidebar: () => void;
|
||||
};
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContext | null>(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<SidebarContext>(
|
||||
() => ({
|
||||
state,
|
||||
open,
|
||||
setOpen,
|
||||
isMobile,
|
||||
openMobile,
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
||||
);
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<TooltipProvider delayDuration={0}>
|
||||
<div
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</SidebarContext.Provider>
|
||||
);
|
||||
}
|
||||
);
|
||||
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 (
|
||||
<div
|
||||
className={cn(
|
||||
"flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||
{/* @ts-expect-error -- SheetContent is not a valid prop */}
|
||||
<SheetContent
|
||||
data-sidebar="sidebar"
|
||||
data-mobile="true"
|
||||
className="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
side={side}
|
||||
>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className="group peer hidden md:block text-sidebar-foreground"
|
||||
data-state={state}
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-variant={variant}
|
||||
data-side={side}
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
className={cn(
|
||||
"duration-200 relative h-svh w-[--sidebar-width] bg-transparent transition-[width] ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]"
|
||||
: "group-data-[collapsible=icon]:w-[--sidebar-width-icon]"
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
className={cn(
|
||||
"duration-200 fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex",
|
||||
side === "left"
|
||||
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
Sidebar.displayName = "Sidebar";
|
||||
|
||||
const SidebarTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof Button>,
|
||||
React.ComponentProps<typeof Button>
|
||||
>(({ className, onClick, ...props }, ref) => {
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<Button
|
||||
ref={ref}
|
||||
data-sidebar="trigger"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn("h-7 w-7", className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event);
|
||||
toggleSidebar();
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<PanelLeft />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
SidebarTrigger.displayName = "SidebarTrigger";
|
||||
|
||||
const SidebarRail = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
React.ComponentProps<"button">
|
||||
>(({ className, ...props }, ref) => {
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
data-sidebar="rail"
|
||||
aria-label="Toggle Sidebar"
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title="Toggle Sidebar"
|
||||
className={cn(
|
||||
"absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex",
|
||||
"[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarRail.displayName = "SidebarRail";
|
||||
|
||||
const SidebarInset = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"main">
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<main
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex min-h-svh flex-1 flex-col bg-white dark:bg-zinc-950",
|
||||
"peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarInset.displayName = "SidebarInset";
|
||||
|
||||
const SidebarInput = React.forwardRef<
|
||||
React.ElementRef<typeof Input>,
|
||||
React.ComponentProps<typeof Input>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<Input
|
||||
ref={ref}
|
||||
data-sidebar="input"
|
||||
className={cn(
|
||||
"h-8 w-full bg-white shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring dark:bg-zinc-950",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarInput.displayName = "SidebarInput";
|
||||
|
||||
const SidebarHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div">
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="header"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarHeader.displayName = "SidebarHeader";
|
||||
|
||||
const SidebarFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div">
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="footer"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarFooter.displayName = "SidebarFooter";
|
||||
|
||||
const SidebarSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof Separator>,
|
||||
React.ComponentProps<typeof Separator>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<Separator
|
||||
ref={ref}
|
||||
data-sidebar="separator"
|
||||
className={cn("mx-2 w-auto bg-sidebar-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarSeparator.displayName = "SidebarSeparator";
|
||||
|
||||
const SidebarContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div">
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="content"
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarContent.displayName = "SidebarContent";
|
||||
|
||||
const SidebarGroup = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div">
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="group"
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarGroup.displayName = "SidebarGroup";
|
||||
|
||||
const SidebarGroupLabel = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div"> & { asChild?: boolean }
|
||||
>(({ className, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "div";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
ref={ref}
|
||||
data-sidebar="group-label"
|
||||
className={cn(
|
||||
"duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarGroupLabel.displayName = "SidebarGroupLabel";
|
||||
|
||||
const SidebarGroupAction = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
React.ComponentProps<"button"> & { asChild?: boolean }
|
||||
>(({ className, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
ref={ref}
|
||||
data-sidebar="group-action"
|
||||
className={cn(
|
||||
"absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 after:md:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarGroupAction.displayName = "SidebarGroupAction";
|
||||
|
||||
const SidebarGroupContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div">
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="group-content"
|
||||
className={cn("w-full text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SidebarGroupContent.displayName = "SidebarGroupContent";
|
||||
|
||||
const SidebarMenu = React.forwardRef<
|
||||
HTMLUListElement,
|
||||
React.ComponentProps<"ul">
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ul
|
||||
ref={ref}
|
||||
data-sidebar="menu"
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SidebarMenu.displayName = "SidebarMenu";
|
||||
|
||||
const SidebarMenuItem = React.forwardRef<
|
||||
HTMLLIElement,
|
||||
React.ComponentProps<"li">
|
||||
>(({ className, ...props }, ref) => (
|
||||
<li
|
||||
ref={ref}
|
||||
data-sidebar="menu-item"
|
||||
className={cn("group/menu-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SidebarMenuItem.displayName = "SidebarMenuItem";
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
outline:
|
||||
"bg-white shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))] dark:bg-zinc-950",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
sm: "h-7 text-xs",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:!p-0",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const SidebarMenuButton = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
React.ComponentProps<"button"> & {
|
||||
asChild?: boolean;
|
||||
isActive?: boolean;
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>
|
||||
>(
|
||||
(
|
||||
{
|
||||
asChild = false,
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
tooltip,
|
||||
className,
|
||||
...props
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
const { isMobile, state } = useSidebar();
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
ref={ref}
|
||||
data-sidebar="menu-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
if (!tooltip) {
|
||||
return button;
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
);
|
||||
SidebarMenuButton.displayName = "SidebarMenuButton";
|
||||
|
||||
const SidebarMenuAction = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
React.ComponentProps<"button"> & {
|
||||
asChild?: boolean;
|
||||
showOnHover?: boolean;
|
||||
}
|
||||
>(({ className, asChild = false, showOnHover = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
ref={ref}
|
||||
data-sidebar="menu-action"
|
||||
className={cn(
|
||||
"absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 after:md:hidden",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
showOnHover &&
|
||||
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarMenuAction.displayName = "SidebarMenuAction";
|
||||
|
||||
const SidebarMenuBadge = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div">
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="menu-badge"
|
||||
className={cn(
|
||||
"absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none",
|
||||
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SidebarMenuBadge.displayName = "SidebarMenuBadge";
|
||||
|
||||
const SidebarMenuSkeleton = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean;
|
||||
}
|
||||
>(({ className, showIcon = false, ...props }, ref) => {
|
||||
// Random width between 50 to 90%.
|
||||
const width = React.useMemo(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sidebar="menu-skeleton"
|
||||
className={cn("rounded-md h-8 flex gap-2 px-2 items-center", className)}
|
||||
{...props}
|
||||
>
|
||||
{showIcon && (
|
||||
<Skeleton
|
||||
className="size-4 rounded-md"
|
||||
data-sidebar="menu-skeleton-icon"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
className="h-4 flex-1 max-w-[--skeleton-width]"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
SidebarMenuSkeleton.displayName = "SidebarMenuSkeleton";
|
||||
|
||||
const SidebarMenuSub = React.forwardRef<
|
||||
HTMLUListElement,
|
||||
React.ComponentProps<"ul">
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ul
|
||||
ref={ref}
|
||||
data-sidebar="menu-sub"
|
||||
className={cn(
|
||||
"mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
SidebarMenuSub.displayName = "SidebarMenuSub";
|
||||
|
||||
const SidebarMenuSubItem = React.forwardRef<
|
||||
HTMLLIElement,
|
||||
React.ComponentProps<"li">
|
||||
>(({ ...props }, ref) => <li ref={ref} {...props} />);
|
||||
SidebarMenuSubItem.displayName = "SidebarMenuSubItem";
|
||||
|
||||
const SidebarMenuSubButton = React.forwardRef<
|
||||
HTMLAnchorElement,
|
||||
React.ComponentProps<"a"> & {
|
||||
asChild?: boolean;
|
||||
size?: "sm" | "md";
|
||||
isActive?: boolean;
|
||||
}
|
||||
>(({ asChild = false, size = "md", isActive, className, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "a";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
ref={ref}
|
||||
data-sidebar="menu-sub-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
||||
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
SidebarMenuSubButton.displayName = "SidebarMenuSubButton";
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupAction,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarInput,
|
||||
SidebarInset,
|
||||
SidebarMenu,
|
||||
SidebarMenuAction,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarMenuSkeleton,
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarRail,
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
};
|
||||
15
frontend/src/components/ui/skeleton.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Skeleton({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<div
|
||||
className={cn("animate-pulse rounded-md bg-zinc-900/10 dark:bg-zinc-50/10", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Skeleton }
|
||||
29
frontend/src/components/ui/switch.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SwitchPrimitives from "@radix-ui/react-switch"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Switch = React.forwardRef<
|
||||
React.ElementRef<typeof SwitchPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SwitchPrimitives.Root
|
||||
className={cn(
|
||||
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-zinc-900 data-[state=unchecked]:bg-zinc-200 dark:focus-visible:ring-zinc-300 dark:focus-visible:ring-offset-zinc-950 dark:data-[state=checked]:bg-zinc-50 dark:data-[state=unchecked]:bg-zinc-800",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<SwitchPrimitives.Thumb
|
||||
className={cn(
|
||||
"pointer-events-none block h-4 w-4 rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0 dark:bg-zinc-950"
|
||||
)}
|
||||
/>
|
||||
</SwitchPrimitives.Root>
|
||||
))
|
||||
Switch.displayName = SwitchPrimitives.Root.displayName
|
||||
|
||||
export { Switch }
|
||||
120
frontend/src/components/ui/table.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Table = React.forwardRef<
|
||||
HTMLTableElement,
|
||||
React.HTMLAttributes<HTMLTableElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div className={cn("relative w-full overflow-auto rounded-md p-3 border bg-white", className)}>
|
||||
<table
|
||||
ref={ref}
|
||||
className="w-full caption-bottom text-sm"
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
Table.displayName = "Table"
|
||||
|
||||
const TableHeader = React.forwardRef<
|
||||
HTMLTableSectionElement,
|
||||
React.HTMLAttributes<HTMLTableSectionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<thead ref={ref} className={cn("bg-stone-50 [&:hover_tr]:!bg-transparent [&_tr]:border-b", className)} {...props} />
|
||||
))
|
||||
TableHeader.displayName = "TableHeader"
|
||||
|
||||
const TableBody = React.forwardRef<
|
||||
HTMLTableSectionElement,
|
||||
React.HTMLAttributes<HTMLTableSectionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<tbody
|
||||
ref={ref}
|
||||
className={cn("[&_tr:last-child]:border-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableBody.displayName = "TableBody"
|
||||
|
||||
const TableFooter = React.forwardRef<
|
||||
HTMLTableSectionElement,
|
||||
React.HTMLAttributes<HTMLTableSectionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<tfoot
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"border-t bg-zinc-100/50 font-medium [&>tr]:last:border-b-0 dark:bg-zinc-800/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableFooter.displayName = "TableFooter"
|
||||
|
||||
const TableRow = React.forwardRef<
|
||||
HTMLTableRowElement,
|
||||
React.HTMLAttributes<HTMLTableRowElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<tr
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"border-none transition-colors hover:bg-fuchsia-100 data-[state=selected]:bg-zinc-100 dark:hover:bg-zinc-800/50 dark:data-[state=selected]:bg-zinc-800",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableRow.displayName = "TableRow"
|
||||
|
||||
const TableHead = React.forwardRef<
|
||||
HTMLTableCellElement,
|
||||
React.ThHTMLAttributes<HTMLTableCellElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<th
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"h-6 px-2 text-black text-left align-middle font-normal text-xs [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px] dark:text-zinc-400",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableHead.displayName = "TableHead"
|
||||
|
||||
const TableCell = React.forwardRef<
|
||||
HTMLTableCellElement,
|
||||
React.TdHTMLAttributes<HTMLTableCellElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<td
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"px-2 py-1 text-t2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableCell.displayName = "TableCell"
|
||||
|
||||
const TableCaption = React.forwardRef<
|
||||
HTMLTableCaptionElement,
|
||||
React.HTMLAttributes<HTMLTableCaptionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<caption
|
||||
ref={ref}
|
||||
className={cn("mt-4 text-sm text-zinc-500 dark:text-zinc-400", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableCaption.displayName = "TableCaption"
|
||||
|
||||
export {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableFooter,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TableCaption,
|
||||
}
|
||||
55
frontend/src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Tabs = TabsPrimitive.Root;
|
||||
|
||||
const TabsList = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-9 items-center justify-center rounded-lg bg-transparent text-zinc-500 dark:bg-zinc-800 dark:text-zinc-400",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
TabsList.displayName = TabsPrimitive.List.displayName;
|
||||
|
||||
const TabsTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-white transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-white data-[state=active]:text-primary data-[state=active]:shadow dark:ring-offset-zinc-950 dark:focus-visible:ring-zinc-300 dark:data-[state=active]:bg-zinc-950 dark:data-[state=active]:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
|
||||
|
||||
const TabsContent = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"mt-2 ring-offset-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 focus-visible:ring-offset-2 dark:ring-offset-zinc-950 dark:focus-visible:ring-zinc-300",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
||||
129
frontend/src/components/ui/toast.tsx
Normal file
@@ -0,0 +1,129 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ToastPrimitives from "@radix-ui/react-toast"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { X } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const ToastProvider = ToastPrimitives.Provider
|
||||
|
||||
const ToastViewport = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Viewport
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
||||
|
||||
const toastVariants = cva(
|
||||
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border border-zinc-200 p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full dark:border-zinc-800",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "border bg-white text-zinc-950 dark:bg-zinc-950 dark:text-zinc-50",
|
||||
destructive:
|
||||
"destructive group border-red-500 bg-red-500 text-zinc-50 dark:border-red-900 dark:bg-red-900 dark:text-zinc-50",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const Toast = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||
VariantProps<typeof toastVariants>
|
||||
>(({ className, variant, ...props }, ref) => {
|
||||
return (
|
||||
<ToastPrimitives.Root
|
||||
ref={ref}
|
||||
className={cn(toastVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
})
|
||||
Toast.displayName = ToastPrimitives.Root.displayName
|
||||
|
||||
const ToastAction = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Action>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Action
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border border-zinc-200 bg-transparent px-3 text-sm font-medium transition-colors hover:bg-zinc-100 focus:outline-none focus:ring-1 focus:ring-zinc-950 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-zinc-100/40 group-[.destructive]:hover:border-red-500/30 group-[.destructive]:hover:bg-red-500 group-[.destructive]:hover:text-zinc-50 group-[.destructive]:focus:ring-red-500 dark:border-zinc-800 dark:hover:bg-zinc-800 dark:focus:ring-zinc-300 dark:group-[.destructive]:border-zinc-800/40 dark:group-[.destructive]:hover:border-red-900/30 dark:group-[.destructive]:hover:bg-red-900 dark:group-[.destructive]:hover:text-zinc-50 dark:group-[.destructive]:focus:ring-red-900",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastAction.displayName = ToastPrimitives.Action.displayName
|
||||
|
||||
const ToastClose = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Close>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Close
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"absolute right-1 top-1 rounded-md p-1 text-zinc-950/50 opacity-0 transition-opacity hover:text-zinc-950 focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600 dark:text-zinc-50/50 dark:hover:text-zinc-50",
|
||||
className
|
||||
)}
|
||||
toast-close=""
|
||||
{...props}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</ToastPrimitives.Close>
|
||||
))
|
||||
ToastClose.displayName = ToastPrimitives.Close.displayName
|
||||
|
||||
const ToastTitle = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Title
|
||||
ref={ref}
|
||||
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
||||
|
||||
const ToastDescription = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm opacity-90", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
||||
|
||||
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
||||
|
||||
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
||||
|
||||
export {
|
||||
type ToastProps,
|
||||
type ToastActionElement,
|
||||
ToastProvider,
|
||||
ToastViewport,
|
||||
Toast,
|
||||
ToastTitle,
|
||||
ToastDescription,
|
||||
ToastClose,
|
||||
ToastAction,
|
||||
}
|
||||
35
frontend/src/components/ui/toaster.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import { useToast } from "@/hooks/use-toast"
|
||||
import {
|
||||
Toast,
|
||||
ToastClose,
|
||||
ToastDescription,
|
||||
ToastProvider,
|
||||
ToastTitle,
|
||||
ToastViewport,
|
||||
} from "@/components/ui/toast"
|
||||
|
||||
export function Toaster() {
|
||||
const { toasts } = useToast()
|
||||
|
||||
return (
|
||||
<ToastProvider>
|
||||
{toasts.map(function ({ id, title, description, action, ...props }) {
|
||||
return (
|
||||
<Toast key={id} {...props}>
|
||||
<div className="grid gap-1">
|
||||
{title && <ToastTitle>{title}</ToastTitle>}
|
||||
{description && (
|
||||
<ToastDescription>{description}</ToastDescription>
|
||||
)}
|
||||
</div>
|
||||
{action}
|
||||
<ToastClose />
|
||||
</Toast>
|
||||
)
|
||||
})}
|
||||
<ToastViewport />
|
||||
</ToastProvider>
|
||||
)
|
||||
}
|
||||
32
frontend/src/components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const TooltipProvider = TooltipPrimitive.Provider
|
||||
|
||||
const Tooltip = TooltipPrimitive.Root
|
||||
|
||||
const TooltipTrigger = TooltipPrimitive.Trigger
|
||||
|
||||
const TooltipContent = React.forwardRef<
|
||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 overflow-hidden rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-zinc-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-zinc-50 dark:text-zinc-900",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</TooltipPrimitive.Portal>
|
||||
))
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||
138
frontend/src/data/stripeCurrencyCodes.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
export const stripeCurrencyCodes = [
|
||||
{ currency: "Afghan Afghani", code: "AFN" },
|
||||
{ currency: "Albanian Lek", code: "ALL" },
|
||||
{ currency: "Algerian Dinar", code: "DZD" },
|
||||
{ currency: "Angolan Kwanza", code: "AOA" },
|
||||
{ currency: "Argentine Peso", code: "ARS" },
|
||||
{ currency: "Armenian Dram", code: "AMD" },
|
||||
{ currency: "Aruban Florin", code: "AWG" },
|
||||
{ currency: "Australian Dollar", code: "AUD" },
|
||||
{ currency: "Azerbaijani Manat", code: "AZN" },
|
||||
{ currency: "Bahamian Dollar", code: "BSD" },
|
||||
{ currency: "Bangladeshi Taka", code: "BDT" },
|
||||
{ currency: "Barbadian Dollar", code: "BBD" },
|
||||
{ currency: "Belize Dollar", code: "BZD" },
|
||||
{ currency: "Bermudian Dollar", code: "BMD" },
|
||||
{ currency: "Bolivian Boliviano", code: "BOB" },
|
||||
{ currency: "Bosnia & Herzegovina Convertible Mark", code: "BAM" },
|
||||
{ currency: "Botswana Pula", code: "BWP" },
|
||||
{ currency: "Brazilian Real", code: "BRL" },
|
||||
{ currency: "British Pound", code: "GBP" },
|
||||
{ currency: "Brunei Dollar", code: "BND" },
|
||||
{ currency: "Bulgarian Lev", code: "BGN" },
|
||||
{ currency: "Burundian Franc", code: "BIF" },
|
||||
{ currency: "Cambodian Riel", code: "KHR" },
|
||||
{ currency: "Canadian Dollar", code: "CAD" },
|
||||
{ currency: "Cape Verdean Escudo", code: "CVE" },
|
||||
{ currency: "Cayman Islands Dollar", code: "KYD" },
|
||||
{ currency: "Central African Cfa Franc", code: "XAF" },
|
||||
{ currency: "Cfp Franc", code: "XPF" },
|
||||
{ currency: "Chilean Peso", code: "CLP" },
|
||||
{ currency: "Chinese Renminbi Yuan", code: "CNY" },
|
||||
{ currency: "Colombian Peso", code: "COP" },
|
||||
{ currency: "Comorian Franc", code: "KMF" },
|
||||
{ currency: "Congolese Franc", code: "CDF" },
|
||||
{ currency: "Costa Rican Colón", code: "CRC" },
|
||||
{ currency: "Croatian Kuna", code: "HRK" },
|
||||
{ currency: "Czech Koruna", code: "CZK" },
|
||||
{ currency: "Danish Krone", code: "DKK" },
|
||||
{ currency: "Djiboutian Franc", code: "DJF" },
|
||||
{ currency: "Dominican Peso", code: "DOP" },
|
||||
{ currency: "East Caribbean Dollar", code: "XCD" },
|
||||
{ currency: "Egyptian Pound", code: "EGP" },
|
||||
{ currency: "Ethiopian Birr", code: "ETB" },
|
||||
{ currency: "Euro", code: "EUR" },
|
||||
{ currency: "Falkland Islands Pound", code: "FKP" },
|
||||
{ currency: "Fijian Dollar", code: "FJD" },
|
||||
{ currency: "Gambian Dalasi", code: "GMD" },
|
||||
{ currency: "Georgian Lari", code: "GEL" },
|
||||
{ currency: "Gibraltar Pound", code: "GIP" },
|
||||
{ currency: "Guatemalan Quetzal", code: "GTQ" },
|
||||
{ currency: "Guinean Franc", code: "GNF" },
|
||||
{ currency: "Guyanese Dollar", code: "GYD" },
|
||||
{ currency: "Haitian Gourde", code: "HTG" },
|
||||
{ currency: "Honduran Lempira", code: "HNL" },
|
||||
{ currency: "Hong Kong Dollar", code: "HKD" },
|
||||
{ currency: "Hungarian Forint", code: "HUF" },
|
||||
{ currency: "Icelandic Króna", code: "ISK" },
|
||||
{ currency: "Indian Rupee", code: "INR" },
|
||||
{ currency: "Indonesian Rupiah", code: "IDR" },
|
||||
{ currency: "Israeli New Sheqel", code: "ILS" },
|
||||
{ currency: "Jamaican Dollar", code: "JMD" },
|
||||
{ currency: "Japanese Yen", code: "JPY" },
|
||||
{ currency: "Kazakhstani Tenge", code: "KZT" },
|
||||
{ currency: "Kenyan Shilling", code: "KES" },
|
||||
{ currency: "Kyrgyzstani Som", code: "KGS" },
|
||||
{ currency: "Lao Kip", code: "LAK" },
|
||||
{ currency: "Lebanese Pound", code: "LBP" },
|
||||
{ currency: "Lesotho Loti", code: "LSL" },
|
||||
{ currency: "Liberian Dollar", code: "LRD" },
|
||||
{ currency: "Macanese Pataca", code: "MOP" },
|
||||
{ currency: "Macedonian Denar", code: "MKD" },
|
||||
{ currency: "Malagasy Ariary", code: "MGA" },
|
||||
{ currency: "Malawian Kwacha", code: "MWK" },
|
||||
{ currency: "Malaysian Ringgit", code: "MYR" },
|
||||
{ currency: "Maldivian Rufiyaa", code: "MVR" },
|
||||
{ currency: "Mauritanian Ouguiya", code: "MRO" },
|
||||
{ currency: "Mauritian Rupee", code: "MUR" },
|
||||
{ currency: "Mexican Peso", code: "MXN" },
|
||||
{ currency: "Moldovan Leu", code: "MDL" },
|
||||
{ currency: "Mongolian Tögrög", code: "MNT" },
|
||||
{ currency: "Moroccan Dirham", code: "MAD" },
|
||||
{ currency: "Mozambican Metical", code: "MZN" },
|
||||
{ currency: "Myanmar Kyat", code: "MMK" },
|
||||
{ currency: "Namibian Dollar", code: "NAD" },
|
||||
{ currency: "Nepalese Rupee", code: "NPR" },
|
||||
{ currency: "Netherlands Antillean Gulden", code: "ANG" },
|
||||
{ currency: "New Taiwan Dollar", code: "TWD" },
|
||||
{ currency: "New Zealand Dollar", code: "NZD" },
|
||||
{ currency: "Nicaraguan Córdoba", code: "NIO" },
|
||||
{ currency: "Nigerian Naira", code: "NGN" },
|
||||
{ currency: "Norwegian Krone", code: "NOK" },
|
||||
{ currency: "Pakistani Rupee", code: "PKR" },
|
||||
{ currency: "Panamanian Balboa", code: "PAB" },
|
||||
{ currency: "Papua New Guinean Kina", code: "PGK" },
|
||||
{ currency: "Paraguayan Guaraní", code: "PYG" },
|
||||
{ currency: "Peruvian Nuevo Sol", code: "PEN" },
|
||||
{ currency: "Philippine Peso", code: "PHP" },
|
||||
{ currency: "Polish Złoty", code: "PLN" },
|
||||
{ currency: "Qatari Riyal", code: "QAR" },
|
||||
{ currency: "Romanian Leu", code: "RON" },
|
||||
{ currency: "Russian Ruble", code: "RUB" },
|
||||
{ currency: "Rwandan Franc", code: "RWF" },
|
||||
{ currency: "São Tomé and Príncipe Dobra", code: "STD" },
|
||||
{ currency: "Saint Helenian Pound", code: "SHP" },
|
||||
{ currency: "Salvadoran Colón", code: "SVC" },
|
||||
{ currency: "Samoan Tala", code: "WST" },
|
||||
{ currency: "Saudi Riyal", code: "SAR" },
|
||||
{ currency: "Serbian Dinar", code: "RSD" },
|
||||
{ currency: "Seychellois Rupee", code: "SCR" },
|
||||
{ currency: "Sierra Leonean Leone", code: "SLL" },
|
||||
{ currency: "Singapore Dollar", code: "SGD" },
|
||||
{ currency: "Solomon Islands Dollar", code: "SBD" },
|
||||
{ currency: "Somali Shilling", code: "SOS" },
|
||||
{ currency: "South African Rand", code: "ZAR" },
|
||||
{ currency: "South Korean Won", code: "KRW" },
|
||||
{ currency: "Sri Lankan Rupee", code: "LKR" },
|
||||
{ currency: "Surinamese Dollar", code: "SRD" },
|
||||
{ currency: "Swazi Lilangeni", code: "SZL" },
|
||||
{ currency: "Swedish Krona", code: "SEK" },
|
||||
{ currency: "Swiss Franc", code: "CHF" },
|
||||
{ currency: "Tajikistani Somoni", code: "TJS" },
|
||||
{ currency: "Tanzanian Shilling", code: "TZS" },
|
||||
{ currency: "Thai Baht", code: "THB" },
|
||||
{ currency: "Tongan Paʻanga", code: "TOP" },
|
||||
{ currency: "Trinidad and Tobago Dollar", code: "TTD" },
|
||||
{ currency: "Turkish Lira", code: "TRY" },
|
||||
{ currency: "Ugandan Shilling", code: "UGX" },
|
||||
{ currency: "Ukrainian Hryvnia", code: "UAH" },
|
||||
{ currency: "United Arab Emirates Dirham", code: "AED" },
|
||||
{ currency: "United States Dollar", code: "USD" },
|
||||
{ currency: "Uruguayan Peso", code: "UYU" },
|
||||
{ currency: "Uzbekistani Som", code: "UZS" },
|
||||
{ currency: "Vanuatu Vatu", code: "VUV" },
|
||||
{ currency: "Vietnamese Đồng", code: "VND" },
|
||||
{ currency: "West African Cfa Franc", code: "XOF" },
|
||||
{ currency: "Yemeni Rial", code: "YER" },
|
||||
{ currency: "Zambian Kwacha", code: "ZMW" },
|
||||
];
|
||||
19
frontend/src/hooks/use-mobile.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
194
frontend/src/hooks/use-toast.ts
Normal file
@@ -0,0 +1,194 @@
|
||||
"use client"
|
||||
|
||||
// Inspired by react-hot-toast library
|
||||
import * as React from "react"
|
||||
|
||||
import type {
|
||||
ToastActionElement,
|
||||
ToastProps,
|
||||
} from "@/components/ui/toast"
|
||||
|
||||
const TOAST_LIMIT = 1
|
||||
const TOAST_REMOVE_DELAY = 1000000
|
||||
|
||||
type ToasterToast = ToastProps & {
|
||||
id: string
|
||||
title?: React.ReactNode
|
||||
description?: React.ReactNode
|
||||
action?: ToastActionElement
|
||||
}
|
||||
|
||||
const actionTypes = {
|
||||
ADD_TOAST: "ADD_TOAST",
|
||||
UPDATE_TOAST: "UPDATE_TOAST",
|
||||
DISMISS_TOAST: "DISMISS_TOAST",
|
||||
REMOVE_TOAST: "REMOVE_TOAST",
|
||||
} as const
|
||||
|
||||
let count = 0
|
||||
|
||||
function genId() {
|
||||
count = (count + 1) % Number.MAX_SAFE_INTEGER
|
||||
return count.toString()
|
||||
}
|
||||
|
||||
type ActionType = typeof actionTypes
|
||||
|
||||
type Action =
|
||||
| {
|
||||
type: ActionType["ADD_TOAST"]
|
||||
toast: ToasterToast
|
||||
}
|
||||
| {
|
||||
type: ActionType["UPDATE_TOAST"]
|
||||
toast: Partial<ToasterToast>
|
||||
}
|
||||
| {
|
||||
type: ActionType["DISMISS_TOAST"]
|
||||
toastId?: ToasterToast["id"]
|
||||
}
|
||||
| {
|
||||
type: ActionType["REMOVE_TOAST"]
|
||||
toastId?: ToasterToast["id"]
|
||||
}
|
||||
|
||||
interface State {
|
||||
toasts: ToasterToast[]
|
||||
}
|
||||
|
||||
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
|
||||
const addToRemoveQueue = (toastId: string) => {
|
||||
if (toastTimeouts.has(toastId)) {
|
||||
return
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
toastTimeouts.delete(toastId)
|
||||
dispatch({
|
||||
type: "REMOVE_TOAST",
|
||||
toastId: toastId,
|
||||
})
|
||||
}, TOAST_REMOVE_DELAY)
|
||||
|
||||
toastTimeouts.set(toastId, timeout)
|
||||
}
|
||||
|
||||
export const reducer = (state: State, action: Action): State => {
|
||||
switch (action.type) {
|
||||
case "ADD_TOAST":
|
||||
return {
|
||||
...state,
|
||||
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
||||
}
|
||||
|
||||
case "UPDATE_TOAST":
|
||||
return {
|
||||
...state,
|
||||
toasts: state.toasts.map((t) =>
|
||||
t.id === action.toast.id ? { ...t, ...action.toast } : t
|
||||
),
|
||||
}
|
||||
|
||||
case "DISMISS_TOAST": {
|
||||
const { toastId } = action
|
||||
|
||||
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
||||
// but I'll keep it here for simplicity
|
||||
if (toastId) {
|
||||
addToRemoveQueue(toastId)
|
||||
} else {
|
||||
state.toasts.forEach((toast) => {
|
||||
addToRemoveQueue(toast.id)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
toasts: state.toasts.map((t) =>
|
||||
t.id === toastId || toastId === undefined
|
||||
? {
|
||||
...t,
|
||||
open: false,
|
||||
}
|
||||
: t
|
||||
),
|
||||
}
|
||||
}
|
||||
case "REMOVE_TOAST":
|
||||
if (action.toastId === undefined) {
|
||||
return {
|
||||
...state,
|
||||
toasts: [],
|
||||
}
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const listeners: Array<(state: State) => void> = []
|
||||
|
||||
let memoryState: State = { toasts: [] }
|
||||
|
||||
function dispatch(action: Action) {
|
||||
memoryState = reducer(memoryState, action)
|
||||
listeners.forEach((listener) => {
|
||||
listener(memoryState)
|
||||
})
|
||||
}
|
||||
|
||||
type Toast = Omit<ToasterToast, "id">
|
||||
|
||||
function toast({ ...props }: Toast) {
|
||||
const id = genId()
|
||||
|
||||
const update = (props: ToasterToast) =>
|
||||
dispatch({
|
||||
type: "UPDATE_TOAST",
|
||||
toast: { ...props, id },
|
||||
})
|
||||
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
|
||||
|
||||
dispatch({
|
||||
type: "ADD_TOAST",
|
||||
toast: {
|
||||
...props,
|
||||
id,
|
||||
open: true,
|
||||
onOpenChange: (open) => {
|
||||
if (!open) dismiss()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
id: id,
|
||||
dismiss,
|
||||
update,
|
||||
}
|
||||
}
|
||||
|
||||
function useToast() {
|
||||
const [state, setState] = React.useState<State>(memoryState)
|
||||
|
||||
React.useEffect(() => {
|
||||
listeners.push(setState)
|
||||
return () => {
|
||||
const index = listeners.indexOf(setState)
|
||||
if (index > -1) {
|
||||
listeners.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}, [state])
|
||||
|
||||
return {
|
||||
...state,
|
||||
toast,
|
||||
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
||||
}
|
||||
}
|
||||
|
||||
export { useToast, toast }
|
||||
6
frontend/src/lib/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
56
frontend/src/middleware.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
clerkClient,
|
||||
clerkMiddleware,
|
||||
createRouteMatcher,
|
||||
currentUser,
|
||||
} from "@clerk/nextjs/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
|
||||
const isProtectedRoute = createRouteMatcher([
|
||||
"/",
|
||||
"/(.*)",
|
||||
|
||||
// "(.*)/features/(.*)",
|
||||
|
||||
// "/admin(.*)",
|
||||
|
||||
// "/workflow/(.*)",
|
||||
// "/cli-auth",
|
||||
// "/credits(.*)",
|
||||
// "/onboarding(.*)",
|
||||
]);
|
||||
|
||||
export default clerkMiddleware(async (auth, req) => {
|
||||
const path = req.nextUrl.pathname;
|
||||
const requestHeaders = new Headers(req.headers);
|
||||
requestHeaders.set("path", path);
|
||||
requestHeaders.set("origin", req.nextUrl.origin);
|
||||
|
||||
if (path === "/") {
|
||||
return NextResponse.redirect(new URL("/customers", req.url));
|
||||
} else if (path === "/sandbox") {
|
||||
return NextResponse.redirect(new URL("/sandbox/customers", req.url));
|
||||
}
|
||||
|
||||
if (path.startsWith("/sandbox")) {
|
||||
const newPath = path.replace("/sandbox", "");
|
||||
requestHeaders.set("env", AppEnv.Sandbox);
|
||||
return NextResponse.rewrite(new URL(newPath, req.url), {
|
||||
headers: requestHeaders,
|
||||
});
|
||||
}
|
||||
|
||||
if (isProtectedRoute(req)) {
|
||||
await auth.protect();
|
||||
}
|
||||
|
||||
requestHeaders.set("env", AppEnv.Live);
|
||||
|
||||
return NextResponse.next({
|
||||
headers: requestHeaders,
|
||||
});
|
||||
});
|
||||
export const config = {
|
||||
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
|
||||
};
|
||||
7
frontend/src/services/CreditService.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
export class CreditService {
|
||||
static async createSystem(axiosInstance: AxiosInstance, data: any) {
|
||||
return await axiosInstance.post("/credits/systems", data);
|
||||
}
|
||||
}
|
||||
13
frontend/src/services/DevService.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
export class DevService {
|
||||
static async createAPIKey(axiosInstance: AxiosInstance, data: any) {
|
||||
const { data: resBody } = await axiosInstance.post("/dev/api_key", data);
|
||||
return resBody;
|
||||
}
|
||||
|
||||
static async deleteAPIKey(axiosInstance: AxiosInstance, id: string) {
|
||||
const { data: resBody } = await axiosInstance.delete(`/dev/api_key/${id}`);
|
||||
return resBody;
|
||||
}
|
||||
}
|
||||
19
frontend/src/services/FeatureService.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
export class FeatureService {
|
||||
static async createFeature(axiosInstance: AxiosInstance, data: any) {
|
||||
return await axiosInstance.post("/v1/features", data);
|
||||
}
|
||||
|
||||
static async updateFeature(
|
||||
axiosInstance: AxiosInstance,
|
||||
featureId: string,
|
||||
data: any
|
||||
) {
|
||||
return await axiosInstance.post(`/v1/features/${featureId}`, data);
|
||||
}
|
||||
|
||||
static async deleteFeature(axiosInstance: AxiosInstance, featureId: string) {
|
||||
return await axiosInstance.delete(`/v1/features/${featureId}`);
|
||||
}
|
||||
}
|
||||
15
frontend/src/services/OrgService.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
export class OrgService {
|
||||
static async get(axiosInstance: AxiosInstance) {
|
||||
return await axiosInstance.get(`/organization`);
|
||||
}
|
||||
|
||||
static async connectStripe(axiosInstance: AxiosInstance, data: any) {
|
||||
return await axiosInstance.post(`/organization/stripe`, data);
|
||||
}
|
||||
|
||||
static async syncStripe(axiosInstance: AxiosInstance) {
|
||||
return await axiosInstance.post(`/organization/sync`);
|
||||
}
|
||||
}
|
||||
8
frontend/src/services/customers/CheckoutService.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
// import { AxiosInstance } from "axios";
|
||||
|
||||
// export const CheckoutService = {
|
||||
// createCheckout: async (axiosInstance: AxiosInstance, data: any) => {
|
||||
// const response = await axiosInstance.post("/v1/checkout", data);
|
||||
// return response.data;
|
||||
// },
|
||||
// };
|
||||
20
frontend/src/services/customers/CusService.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
import { Customer } from "@autumn/shared";
|
||||
|
||||
export class CusService {
|
||||
static async createCustomer(axios: AxiosInstance, data: any) {
|
||||
await axios.post("/v1/customers", data);
|
||||
}
|
||||
|
||||
static async deleteCustomer(axios: AxiosInstance, customer_id: string) {
|
||||
await axios.delete(`/v1/customers/${customer_id}`);
|
||||
}
|
||||
|
||||
static async addProduct(
|
||||
axios: AxiosInstance,
|
||||
customer_id: string,
|
||||
data: any
|
||||
) {
|
||||
return await axios.post(`/v1/customers/${customer_id}/products`, data);
|
||||
}
|
||||
}
|
||||
11
frontend/src/services/products/PriceService.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
export class PriceService {
|
||||
static async createPrice(axiosInstance: AxiosInstance, data: any) {
|
||||
await axiosInstance.post(`/v1/prices`, data);
|
||||
}
|
||||
|
||||
static async deletePrice(axiosInstance: AxiosInstance, priceId: string) {
|
||||
await axiosInstance.delete(`/v1/prices/${priceId}`);
|
||||
}
|
||||
}
|
||||
32
frontend/src/services/products/ProductService.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import axios, { AxiosInstance } from "axios";
|
||||
|
||||
export class ProductService {
|
||||
static async createProduct(axiosInstance: AxiosInstance, data: any) {
|
||||
const response = await axiosInstance.post("/v1/products", data);
|
||||
return response.data.product_id;
|
||||
}
|
||||
|
||||
static async updateProduct(
|
||||
axiosInstance: AxiosInstance,
|
||||
productId: string,
|
||||
data: any
|
||||
) {
|
||||
await axiosInstance.post(`/v1/products/${productId}`, data);
|
||||
}
|
||||
|
||||
static async deleteProduct(axiosInstance: AxiosInstance, productId: string) {
|
||||
await axiosInstance.delete(`/v1/products/${productId}`);
|
||||
}
|
||||
|
||||
static async createEntitlement(axiosInstance: AxiosInstance, data: any) {
|
||||
await axiosInstance.post(`/v1/entitlements`, data);
|
||||
}
|
||||
|
||||
static async createPrice(
|
||||
axiosInstance: AxiosInstance,
|
||||
productId: string,
|
||||
data: any
|
||||
) {
|
||||
await axiosInstance.post(`/products/${productId}/prices`, data);
|
||||
}
|
||||
}
|
||||
40
frontend/src/services/useAxiosInstance.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { endpoint } from "@/utils/constants";
|
||||
import { useAuth } from "@clerk/nextjs";
|
||||
import axios from "axios";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
|
||||
export function useAxiosInstance({
|
||||
env,
|
||||
isAuth = true,
|
||||
}: {
|
||||
env: AppEnv;
|
||||
isAuth?: boolean;
|
||||
}) {
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: endpoint,
|
||||
});
|
||||
|
||||
const { getToken } = useAuth();
|
||||
|
||||
if (isAuth) {
|
||||
axiosInstance.interceptors.request.use(
|
||||
async (config) => {
|
||||
const token = await getToken({
|
||||
template: "custom_template",
|
||||
});
|
||||
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
config.headers["app_env"] = env;
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return axiosInstance;
|
||||
}
|
||||
70
frontend/src/services/useAxiosSwr.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import useSWR, { SWRConfiguration } from "swr";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useAuth } from "@clerk/nextjs";
|
||||
import { useAxiosInstance } from "./useAxiosInstance";
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
|
||||
// export function useClerkToken() {
|
||||
// const { getToken } = useAuth();
|
||||
// const [token, setToken] = useState<string | null>(null);
|
||||
|
||||
// useEffect(() => {
|
||||
// const fetchToken = async () => {
|
||||
// const fetchedToken = await getToken();
|
||||
// setToken(fetchedToken);
|
||||
// };
|
||||
|
||||
// fetchToken();
|
||||
// }, [getToken]);
|
||||
|
||||
// return token;
|
||||
// }
|
||||
|
||||
export function useAxiosSWR({
|
||||
url,
|
||||
env,
|
||||
withAuth = true,
|
||||
options = {},
|
||||
}: {
|
||||
url: string;
|
||||
env: AppEnv;
|
||||
withAuth?: boolean;
|
||||
options?: SWRConfiguration;
|
||||
}) {
|
||||
const axiosInstance = useAxiosInstance({ env, isAuth: withAuth });
|
||||
|
||||
const fetcher = async (url: string) => {
|
||||
try {
|
||||
const res = await axiosInstance.get(url);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return useSWR(url, fetcher, {
|
||||
refreshInterval: 0,
|
||||
revalidateOnFocus: false,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
// export function useAuthenticatedPostSWR<T>(
|
||||
// url: string,
|
||||
// appEnv: AppEnv,
|
||||
// data: any,
|
||||
// isAuth = true
|
||||
// ) {
|
||||
// const axiosInstance = useAxiosInstance(appEnv, isAuth);
|
||||
|
||||
// const fetcher = async (url: string) => {
|
||||
// try {
|
||||
// let res = await axiosInstance.post(url, data);
|
||||
// return res.data;
|
||||
// } catch (error) {
|
||||
// throw error;
|
||||
// }
|
||||
// };
|
||||
|
||||
// return useSWR(url, fetcher);
|
||||
// }
|
||||
6
frontend/src/utils/constants.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// export const endpoint = "http://localhost:8080";
|
||||
|
||||
export const endpoint = process.env.NEXT_PUBLIC_BACKEND_URL;
|
||||
// process.env.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
// ? "https://recase-express.onrender.com"
|
||||
// : "http://localhost:8080";
|
||||
19
frontend/src/utils/formatUtils/formatDateUtils.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { format } from "date-fns";
|
||||
|
||||
export const formatTimestamp = (timestamp: number | null | undefined) => {
|
||||
if (!timestamp) return "";
|
||||
return format(new Date(timestamp), "MM/dd/yyyy");
|
||||
};
|
||||
|
||||
export const formatUnixToDateTime = (unix: number | null | undefined) => {
|
||||
if (!unix) return { date: "", time: "" };
|
||||
const date = format(new Date(unix), "d MMM yy");
|
||||
const time = format(new Date(unix), "hh:mm a");
|
||||
return { date, time };
|
||||
};
|
||||
|
||||
export const formatUnixToDateTimeString = (unix: number | null | undefined) => {
|
||||
if (!unix) return "";
|
||||
const { date, time } = formatUnixToDateTime(unix);
|
||||
return `${date} ${time}`;
|
||||
};
|
||||
21
frontend/src/utils/formatUtils/formatTextUtils.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export const keyToTitle = (key: string) => {
|
||||
return key.replace(/_/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
||||
};
|
||||
|
||||
export const keyToTitleFirstCaps = (key: string) => {
|
||||
// Capitalize first char
|
||||
const res = key.replace(/^\w/, (char) => char.toUpperCase());
|
||||
// Replace underscores with spaces
|
||||
return res.replace(/_/g, " ");
|
||||
};
|
||||
|
||||
export const slugify = (text: string) => {
|
||||
return text.toLowerCase().replace(/ /g, "-");
|
||||
};
|
||||
|
||||
export const formatCurrency = (amount: number, currency: string = "USD") => {
|
||||
return new Intl.NumberFormat("en-US", {
|
||||
style: "currency",
|
||||
currency: currency,
|
||||
}).format(amount);
|
||||
};
|
||||
61
frontend/src/utils/genUtils.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { AppEnv } from "@autumn/shared";
|
||||
|
||||
export const invalidNumber = (value: any) => {
|
||||
return isNaN(parseFloat(value));
|
||||
};
|
||||
|
||||
export const getBackendErr = (error: any, defaultText: string) => {
|
||||
if (error.response && error.response.data) {
|
||||
const data = error.response.data;
|
||||
if (data.message && data.code) {
|
||||
return data.message;
|
||||
} else {
|
||||
return defaultText;
|
||||
}
|
||||
} else {
|
||||
return defaultText;
|
||||
}
|
||||
};
|
||||
|
||||
export const getBackendErrObj = (error: any) => {
|
||||
if (error.response && error.response.data) {
|
||||
const data = error.response.data;
|
||||
if (data.code) {
|
||||
return { code: data.code, message: data.message };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const getEnvFromPath = (path: string) => {
|
||||
if (path.includes("/sandbox")) {
|
||||
return AppEnv.Sandbox;
|
||||
}
|
||||
return AppEnv.Live;
|
||||
};
|
||||
|
||||
export const envToPath = (env: AppEnv, currentPath: string) => {
|
||||
if (env === AppEnv.Sandbox && !currentPath.includes("/sandbox")) {
|
||||
return `/sandbox${currentPath}`;
|
||||
} else if (env === AppEnv.Live && currentPath.includes("/sandbox")) {
|
||||
return currentPath.replace("/sandbox", "");
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const navigateTo = (path: string, router: any, env: AppEnv) => {
|
||||
if (env === AppEnv.Sandbox) {
|
||||
router.push(`/sandbox${path}`);
|
||||
} else {
|
||||
router.push(path);
|
||||
}
|
||||
};
|
||||
|
||||
export const getRedirectUrl = (path: string, env: AppEnv) => {
|
||||
if (env === AppEnv.Sandbox) {
|
||||
return `/sandbox${path}`;
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
};
|
||||
27
frontend/src/utils/product/priceUtils.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BillingInterval } from "@autumn/shared";
|
||||
|
||||
import { FixedPriceConfig, Price, UsagePriceConfig } from "@autumn/shared";
|
||||
|
||||
export const validBillingInterval = (
|
||||
prices: Price[],
|
||||
config: FixedPriceConfig | UsagePriceConfig
|
||||
) => {
|
||||
const interval1 = config.interval;
|
||||
if (!interval1 || interval1 == BillingInterval.OneOff) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const price of prices) {
|
||||
const interval2 = price.config?.interval;
|
||||
|
||||
if (!interval2 || interval2 == BillingInterval.OneOff) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (interval1 != interval2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
33
frontend/src/utils/serverUtils.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { auth, clerkClient } from "@clerk/nextjs/server";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Organization } from "@autumn/shared";
|
||||
export const onboardingComplete = async () => {
|
||||
const authData = await auth();
|
||||
const clerkCli = await clerkClient();
|
||||
if (!authData.orgId) {
|
||||
return redirect("/onboarding");
|
||||
}
|
||||
|
||||
const org = await clerkCli.organizations.getOrganization({
|
||||
organizationId: authData.orgId!,
|
||||
});
|
||||
|
||||
const meta = org.privateMetadata as any;
|
||||
if (!meta.stripe?.connected) {
|
||||
return redirect("/onboarding");
|
||||
}
|
||||
|
||||
return org;
|
||||
};
|
||||
|
||||
export const getOrgFromSession = async () => {
|
||||
const { sessionClaims }: { sessionClaims: any } = await auth();
|
||||
|
||||
const org: Organization = {
|
||||
id: sessionClaims?.org?.id,
|
||||
default_currency: sessionClaims?.org?.default_currency,
|
||||
stripe_connected: sessionClaims?.org?.stripe_connected,
|
||||
};
|
||||
|
||||
return org;
|
||||
};
|
||||
8
frontend/src/utils/supabase/client.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createBrowserClient } from "@supabase/ssr";
|
||||
|
||||
export function createClient() {
|
||||
return createBrowserClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||
);
|
||||
}
|
||||
29
frontend/src/utils/supabase/server.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createServerClient, type CookieOptions } from "@supabase/ssr";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function createClient() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{
|
||||
cookies: {
|
||||
getAll() {
|
||||
return cookieStore.getAll();
|
||||
},
|
||||
setAll(cookiesToSet) {
|
||||
try {
|
||||
cookiesToSet.forEach(({ name, value, options }) =>
|
||||
cookieStore.set(name, value, options)
|
||||
);
|
||||
} catch {
|
||||
// The `setAll` method was called from a Server Component.
|
||||
// This can be ignored if you have middleware refreshing
|
||||
// user sessions.
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
13
frontend/src/views/HomeContext.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const HomeContext = createContext<any>(null);
|
||||
|
||||
export const useHomeContext = () => {
|
||||
const context = useContext(HomeContext);
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error("useHomeContext must be used within a HomeContextProvider");
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
52
frontend/src/views/HomeView.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
|
||||
import { HomeContext } from "./HomeContext";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
import { useOrganization, useUser } from "@clerk/nextjs";
|
||||
import CreateOrgView from "./onboarding/CreateOrgView";
|
||||
|
||||
export enum HomeTab {
|
||||
Features = "features",
|
||||
Credits = "credits",
|
||||
Plans = "plans",
|
||||
Developer = "developer",
|
||||
}
|
||||
|
||||
function HomeView() {
|
||||
const [activeTab, setActiveTab] = useState(HomeTab.Plans);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { isLoaded: userLoaded, user } = useUser();
|
||||
const { isLoaded: orgLoaded, organization } = useOrganization();
|
||||
|
||||
if (!organization) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-screen">
|
||||
<CreateOrgView />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<HomeContext.Provider
|
||||
value={{
|
||||
activeTab,
|
||||
setActiveTab,
|
||||
error,
|
||||
setError,
|
||||
}}
|
||||
>
|
||||
<Toaster
|
||||
position="bottom-center"
|
||||
toastOptions={{
|
||||
duration: 1000,
|
||||
style: { fontSize: "14px" },
|
||||
}}
|
||||
/>
|
||||
</HomeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default HomeView;
|
||||
249
frontend/src/views/credits/CreateCreditSystem.tsx
Normal file
@@ -0,0 +1,249 @@
|
||||
import FieldLabel from "@/components/general/modal-components/FieldLabel";
|
||||
import { SelectContent } from "@/components/ui/select";
|
||||
import { SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SelectItem } from "@/components/ui/select";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogTrigger,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Select } from "@/components/ui/select";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { FeatureService } from "@/services/FeatureService";
|
||||
import { useAxiosInstance } from "@/services/useAxiosInstance";
|
||||
import toast from "react-hot-toast";
|
||||
import { slugify } from "@/utils/formatUtils/formatTextUtils";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faXmark } from "@fortawesome/pro-solid-svg-icons";
|
||||
import { useCreditsContext } from "./CreditsContext";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
import { Feature, FeatureType, CreditSystemConfig } from "@autumn/shared";
|
||||
import { getBackendErr } from "@/utils/genUtils";
|
||||
|
||||
const defaultFields = {
|
||||
name: "",
|
||||
id: "",
|
||||
};
|
||||
|
||||
const defaultConfig = {
|
||||
schema: [{ metered_feature_id: "", feature_amount: 0, credit_amount: 0 }],
|
||||
};
|
||||
|
||||
function CreateCreditSystem() {
|
||||
const { features, mutate, env } = useCreditsContext();
|
||||
const axiosInstance = useAxiosInstance({ env: env });
|
||||
|
||||
const [fields, setFields] = useState(defaultFields);
|
||||
const [creditSystemConfig, setCreditSystemConfig] =
|
||||
useState<CreditSystemConfig>(defaultConfig);
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [idChanged, setIdChanged] = useState(false);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setFields(defaultFields);
|
||||
setCreditSystemConfig(defaultConfig);
|
||||
setIdChanged(false);
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!fields.id || !fields.name) {
|
||||
toast.error("Please fill in all fields");
|
||||
return;
|
||||
}
|
||||
|
||||
if (creditSystemConfig.schema.length === 0) {
|
||||
toast.error("Need at least one metered feature");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const item of creditSystemConfig.schema) {
|
||||
if (!item.metered_feature_id) {
|
||||
toast.error("Select a metered feature");
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.feature_amount <= 0 || item.credit_amount <= 0) {
|
||||
toast.error("Feature amount and credit amount must be greater than 0");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await FeatureService.createFeature(axiosInstance, {
|
||||
name: fields.name,
|
||||
id: fields.id,
|
||||
type: FeatureType.CreditSystem,
|
||||
config: creditSystemConfig,
|
||||
});
|
||||
await mutate();
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
toast.error(getBackendErr(error, "Failed to create credit system"));
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
const addSchemaItem = () => {
|
||||
setCreditSystemConfig({
|
||||
...creditSystemConfig,
|
||||
schema: [
|
||||
...creditSystemConfig.schema,
|
||||
{ metered_feature_id: "", feature_amount: 0, credit_amount: 0 },
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
const removeSchemaItem = (index: number) => {
|
||||
setCreditSystemConfig({
|
||||
...creditSystemConfig,
|
||||
schema: creditSystemConfig.schema.filter((_, i) => i !== index),
|
||||
});
|
||||
};
|
||||
|
||||
const handleSchemaChange = (index: number, field: string, value: string) => {
|
||||
const newSchema = [...creditSystemConfig.schema];
|
||||
newSchema[index] = { ...newSchema[index], [field]: value };
|
||||
setCreditSystemConfig({ ...creditSystemConfig, schema: newSchema });
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="dashed"
|
||||
className="w-full"
|
||||
startIcon={<PlusIcon size={15} />}
|
||||
>
|
||||
Create Credit System
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="w-[500px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create Credit System</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex gap-4 w-full">
|
||||
<div className="w-full">
|
||||
<FieldLabel>Name</FieldLabel>
|
||||
<Input
|
||||
placeholder="Name"
|
||||
value={fields.name}
|
||||
onChange={(e) => {
|
||||
const newFields: any = { ...fields, name: e.target.value };
|
||||
if (!idChanged) {
|
||||
newFields.id = slugify(e.target.value);
|
||||
}
|
||||
setFields(newFields);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<FieldLabel>ID</FieldLabel>
|
||||
<Input
|
||||
placeholder="ID"
|
||||
value={fields.id}
|
||||
onChange={(e) => {
|
||||
setFields({ ...fields, id: e.target.value });
|
||||
setIdChanged(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<FieldLabel>Schema</FieldLabel>
|
||||
|
||||
<div className="grid grid-cols-10 gap-2 gap-y-1 mb-4">
|
||||
<FieldLabel className="!mb-0 col-span-3">Meter</FieldLabel>
|
||||
<FieldLabel className="!mb-0 col-span-3">
|
||||
Metered Amount
|
||||
</FieldLabel>
|
||||
<FieldLabel className="!mb-0 col-span-3">
|
||||
Credit Amount
|
||||
</FieldLabel>
|
||||
<p className="col-span-1"></p>
|
||||
|
||||
{creditSystemConfig.schema.map((item, index) => (
|
||||
<React.Fragment key={index}>
|
||||
<Select
|
||||
onValueChange={(value) => {
|
||||
handleSchemaChange(index, "metered_feature_id", value);
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="col-span-3">
|
||||
<SelectValue placeholder="eg. API Calls" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{features
|
||||
?.filter(
|
||||
(feature: Feature) =>
|
||||
feature.type === FeatureType.Metered
|
||||
)
|
||||
.map((feature: Feature) => (
|
||||
<SelectItem key={feature.id} value={feature.id!}>
|
||||
{feature.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Input
|
||||
className="col-span-3"
|
||||
type="number"
|
||||
value={item.feature_amount}
|
||||
onChange={(e) =>
|
||||
handleSchemaChange(
|
||||
index,
|
||||
"feature_amount",
|
||||
e.target.value
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
className="col-span-3"
|
||||
type="number"
|
||||
value={item.credit_amount}
|
||||
onChange={(e) =>
|
||||
handleSchemaChange(index, "credit_amount", e.target.value)
|
||||
}
|
||||
/>
|
||||
<div className="col-span-1 flex items-center justify-end">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => removeSchemaItem(index)}
|
||||
isIcon
|
||||
dim={6}
|
||||
className="text-t3"
|
||||
>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
</Button>
|
||||
</div>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Button variant="secondary" onClick={addSchemaItem}>
|
||||
Add
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button onClick={handleSubmit} isLoading={isLoading} variant="gradientPrimary">
|
||||
Create
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default CreateCreditSystem;
|
||||
78
frontend/src/views/credits/CreditSystemRowToolbar.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import SmallSpinner from "@/components/general/SmallSpinner";
|
||||
import { faEllipsisVertical, faTrash } from "@fortawesome/pro-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { cn } from "@nextui-org/theme";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
import { useAxiosInstance } from "@/services/useAxiosInstance";
|
||||
import { Feature } from "@autumn/shared";
|
||||
import { FeatureService } from "@/services/FeatureService";
|
||||
import { getBackendErr } from "@/utils/genUtils";
|
||||
import { useCreditsContext } from "./CreditsContext";
|
||||
|
||||
export const CreditSystemRowToolbar = ({
|
||||
className,
|
||||
creditSystem,
|
||||
}: {
|
||||
className?: string;
|
||||
creditSystem: Feature;
|
||||
}) => {
|
||||
const { env, mutate } = useCreditsContext();
|
||||
const axiosInstance = useAxiosInstance({ env });
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const handleDelete = async () => {
|
||||
setDeleteLoading(true);
|
||||
try {
|
||||
await FeatureService.deleteFeature(axiosInstance, creditSystem.id);
|
||||
await mutate();
|
||||
} catch (error) {
|
||||
toast.error(getBackendErr(error, "Failed to delete feature"));
|
||||
}
|
||||
|
||||
setDeleteLoading(false);
|
||||
setDeleteOpen(false);
|
||||
};
|
||||
return (
|
||||
<DropdownMenu open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
isIcon
|
||||
variant="ghost"
|
||||
dim={6}
|
||||
className={cn("rounded-full", className)}
|
||||
>
|
||||
<FontAwesomeIcon icon={faEllipsisVertical} size="sm" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="text-t2">
|
||||
<DropdownMenuItem
|
||||
className="flex items-center"
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
await handleDelete();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between w-full gap-2">
|
||||
Delete
|
||||
{deleteLoading ? (
|
||||
<SmallSpinner />
|
||||
) : (
|
||||
<FontAwesomeIcon icon={faTrash} size="sm" />
|
||||
)}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
};
|
||||
64
frontend/src/views/credits/CreditSystemsTable.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import { formatUnixToDateTime } from "@/utils/formatUtils/formatDateUtils";
|
||||
import { Feature, Product } from "@autumn/shared";
|
||||
import React from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableBody,
|
||||
TableCell,
|
||||
} from "@/components/ui/table";
|
||||
import { CreditSystemRowToolbar } from "./CreditSystemRowToolbar";
|
||||
|
||||
export const CreditSystemsTable = ({
|
||||
creditSystems,
|
||||
}: {
|
||||
creditSystems: Feature[];
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader className="rounded-full">
|
||||
<TableRow>
|
||||
<TableHead className="">Credit System Name</TableHead>
|
||||
<TableHead>System ID</TableHead>
|
||||
<TableHead>Meters</TableHead>
|
||||
<TableHead>Created At</TableHead>
|
||||
<TableHead className="w-20"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{creditSystems.map((creditSystem) => (
|
||||
<TableRow key={creditSystem.id}>
|
||||
<TableCell className="min-w-32 font-medium">
|
||||
{creditSystem.name}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-32 font-mono text-t2">
|
||||
{" "}
|
||||
{creditSystem.id}{" "}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-32 font-mono text-t2 w-full">
|
||||
{creditSystem.config.schema
|
||||
.map((schema: any) => schema.metered_feature_id)
|
||||
.join(", ")}{" "}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-48">
|
||||
{formatUnixToDateTime(creditSystem.created_at).date}
|
||||
<span className="text-t3">
|
||||
{" "}
|
||||
{formatUnixToDateTime(creditSystem.created_at).time}{" "}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="w-20 ">
|
||||
<CreditSystemRowToolbar creditSystem={creditSystem} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
};
|
||||
47
frontend/src/views/credits/CreditSystemsView.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import React, { useContext } from "react";
|
||||
|
||||
import { AppEnv, DBConnection, Feature, FeatureType } from "@autumn/shared";
|
||||
import CreateCreditSystem from "./CreateCreditSystem";
|
||||
import { useFeaturesContext } from "../features/FeaturesContext";
|
||||
import { useAxiosSWR } from "@/services/useAxiosSwr";
|
||||
import LoadingScreen from "../general/LoadingScreen";
|
||||
import { CreditsContext } from "./CreditsContext";
|
||||
import { CreditSystemsTable } from "./CreditSystemsTable";
|
||||
import { CustomToaster } from "@/components/general/CustomToaster";
|
||||
|
||||
function CreditSystemsView({ env }: { env: AppEnv }) {
|
||||
const { data, isLoading, error, mutate } = useAxiosSWR({
|
||||
url: "/features",
|
||||
env: env,
|
||||
});
|
||||
|
||||
if (isLoading) return <LoadingScreen />;
|
||||
|
||||
const creditSystems = data?.features.filter(
|
||||
(feature) => feature.type === FeatureType.CreditSystem
|
||||
);
|
||||
|
||||
return (
|
||||
<CreditsContext.Provider
|
||||
value={{
|
||||
features: data?.features,
|
||||
env: env,
|
||||
mutate,
|
||||
}}
|
||||
>
|
||||
<CustomToaster />
|
||||
<div>
|
||||
<h1 className="text-xl font-medium">Credits</h1>
|
||||
<p className="text-sm text-t2">
|
||||
Define the credit systems your users are entitled to
|
||||
</p>
|
||||
</div>
|
||||
<CreditSystemsTable creditSystems={creditSystems} />
|
||||
<CreateCreditSystem />
|
||||
</CreditsContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default CreditSystemsView;
|
||||
15
frontend/src/views/credits/CreditsContext.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const CreditsContext = createContext<any>(null);
|
||||
|
||||
export const useCreditsContext = () => {
|
||||
const context = useContext(CreditsContext);
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
"useCreditsContext must be used within a CreditsContextProvider"
|
||||
);
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
94
frontend/src/views/customers/CreateCustomer.tsx
Normal file
@@ -0,0 +1,94 @@
|
||||
import FieldLabel from "@/components/general/modal-components/FieldLabel";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogTitle,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTrigger,
|
||||
DialogFooter,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { CusService } from "@/services/customers/CusService";
|
||||
import { useAxiosInstance } from "@/services/useAxiosInstance";
|
||||
import React, { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useCustomersContext } from "./CustomersContext";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
import { getBackendErr, navigateTo } from "@/utils/genUtils";
|
||||
|
||||
function CreateCustomer() {
|
||||
const { env } = useCustomersContext();
|
||||
const router = useRouter();
|
||||
const axiosInstance = useAxiosInstance({ env });
|
||||
const [fields, setFields] = useState<{ [key: string]: string }>({
|
||||
name: "",
|
||||
id: "",
|
||||
email: "",
|
||||
});
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleCreate = async () => {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
await CusService.createCustomer(axiosInstance, fields);
|
||||
toast.success("Customer created successfully");
|
||||
navigateTo(`/customers/${fields.id}`, router, env);
|
||||
} catch (error) {
|
||||
toast.error(getBackendErr(error, "Failed to create customer"));
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="dashed"
|
||||
className="w-full"
|
||||
startIcon={<PlusIcon size={15} />}
|
||||
>
|
||||
Create Customer
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="w-[400px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create Customer</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="flex gap-2">
|
||||
<div>
|
||||
<FieldLabel>Name</FieldLabel>
|
||||
<Input
|
||||
value={fields.name}
|
||||
onChange={(e) => setFields({ ...fields, name: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<FieldLabel>ID</FieldLabel>
|
||||
<Input
|
||||
value={fields.id}
|
||||
onChange={(e) => setFields({ ...fields, id: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<FieldLabel>Email</FieldLabel>
|
||||
<Input
|
||||
value={fields.email}
|
||||
onChange={(e) => setFields({ ...fields, email: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button onClick={handleCreate} isLoading={isLoading} variant="gradientPrimary">
|
||||
Create
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default CreateCustomer;
|
||||
15
frontend/src/views/customers/CustomersContext.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const CustomersContext = createContext<any>(null);
|
||||
|
||||
export const useCustomersContext = () => {
|
||||
const context = useContext(CustomersContext);
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
"useCustomersContext must be used within a CustomersContextProvider"
|
||||
);
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
65
frontend/src/views/customers/CustomersTable.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import { formatUnixToDateTime } from "@/utils/formatUtils/formatDateUtils";
|
||||
import { Customer, Product } from "@autumn/shared";
|
||||
import React from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableBody,
|
||||
TableCell,
|
||||
} from "@/components/ui/table";
|
||||
import { navigateTo } from "@/utils/genUtils";
|
||||
import { useCustomersContext } from "./CustomersContext";
|
||||
|
||||
export const CustomersTable = ({ customers }: { customers: Customer[] }) => {
|
||||
const { env } = useCustomersContext();
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader className="rounded-full">
|
||||
<TableRow>
|
||||
<TableHead className="">Customer</TableHead>
|
||||
<TableHead>Customer ID</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Created At</TableHead>
|
||||
<TableHead className="w-20"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{customers.map((customer) => (
|
||||
<TableRow
|
||||
key={customer.id}
|
||||
className="cursor-pointer"
|
||||
onClick={() => navigateTo(`/customers/${customer.id}`, router, env)}
|
||||
>
|
||||
<TableCell className="min-w-32 font-medium">
|
||||
{customer.name}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-32 font-mono text-t2">
|
||||
{" "}
|
||||
{customer.id}{" "}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-32 font-mono text-t2 w-full">
|
||||
{" "}
|
||||
{customer.email}{" "}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-48">
|
||||
{formatUnixToDateTime(customer.created_at).date}
|
||||
<span className="text-t3">
|
||||
{" "}
|
||||
{formatUnixToDateTime(customer.created_at).time}{" "}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="w-20 ">
|
||||
{/* <ProductRowToolbar product={product} /> */}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
};
|
||||
42
frontend/src/views/customers/CustomersView.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import { AppEnv, Customer } from "@autumn/shared";
|
||||
import React from "react";
|
||||
import CreateCustomer from "./CreateCustomer";
|
||||
import { useAxiosSWR } from "@/services/useAxiosSwr";
|
||||
import LoadingScreen from "../general/LoadingScreen";
|
||||
import { CustomersContext } from "./CustomersContext";
|
||||
import Link from "next/link";
|
||||
import { CustomToaster } from "@/components/general/CustomToaster";
|
||||
import { CustomersTable } from "./CustomersTable";
|
||||
|
||||
function CustomersView({ env }: { env: AppEnv }) {
|
||||
const { data, isLoading, error, mutate } = useAxiosSWR({
|
||||
url: `/customers`,
|
||||
env,
|
||||
});
|
||||
|
||||
if (isLoading) return <LoadingScreen />;
|
||||
|
||||
const { customers } = data;
|
||||
// console.log(data);
|
||||
// console.log(customers);
|
||||
|
||||
return (
|
||||
<CustomersContext.Provider value={{ customers, env, mutate }}>
|
||||
<CustomToaster />
|
||||
<h1 className="text-xl font-medium">Customers</h1>
|
||||
{customers?.length > 0 ? (
|
||||
<CustomersTable customers={customers} />
|
||||
) : (
|
||||
<div className=" flex flex-col text-center text-t3">
|
||||
<span>You don't have any customers</span>
|
||||
<span className="text-t3 text-sm">...yet</span>
|
||||
</div>
|
||||
)}
|
||||
<CreateCustomer />
|
||||
</CustomersContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default CustomersView;
|
||||
15
frontend/src/views/customers/customer/CustomerContext.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const CustomerContext = createContext<any>(null);
|
||||
|
||||
export const useCustomerContext = () => {
|
||||
const context = useContext(CustomerContext);
|
||||
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
"useCustomerContext must be used within a CustomerContextProvider"
|
||||
);
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { CusProduct } from "@autumn/shared";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export const CustomerProductList = ({
|
||||
customer,
|
||||
products,
|
||||
}: {
|
||||
customer: any;
|
||||
products: any;
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Table className="p-2">
|
||||
<TableHeader className="bg-transparent">
|
||||
<TableRow className="">
|
||||
<TableHead className="w-[150px]">Name</TableHead>
|
||||
<TableHead className="">Product ID</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{customer.products.map((cusProduct: CusProduct) => {
|
||||
return (
|
||||
<TableRow
|
||||
key={cusProduct.id}
|
||||
className="cursor-pointer"
|
||||
onClick={() => {
|
||||
router.push(
|
||||
`/customers/${customer.id}/${cusProduct.product_id}`
|
||||
);
|
||||
}}
|
||||
>
|
||||
<TableCell>
|
||||
{products.find((p) => p.id === cusProduct.product_id)?.name}
|
||||
</TableCell>
|
||||
<TableCell>{cusProduct.product_id}</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
81
frontend/src/views/customers/customer/CustomerToolbar.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
import SmallSpinner from "@/components/general/SmallSpinner";
|
||||
import { faEllipsisVertical, faTrash } from "@fortawesome/pro-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { cn } from "@nextui-org/theme";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAxiosInstance } from "@/services/useAxiosInstance";
|
||||
import { Customer } from "@autumn/shared";
|
||||
import { useCustomerContext } from "./CustomerContext";
|
||||
import { CusService } from "@/services/customers/CusService";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { faCog } from "@fortawesome/pro-duotone-svg-icons";
|
||||
import { navigateTo } from "@/utils/genUtils";
|
||||
|
||||
export const CustomerToolbar = ({
|
||||
className,
|
||||
customer,
|
||||
}: {
|
||||
className?: string;
|
||||
customer: Customer;
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
const { mutate, env } = useCustomerContext();
|
||||
|
||||
const axiosInstance = useAxiosInstance({ env });
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const handleDelete = async () => {
|
||||
setDeleteLoading(true);
|
||||
try {
|
||||
await CusService.deleteCustomer(axiosInstance, customer.id);
|
||||
navigateTo("/customers", router, env);
|
||||
} catch (error) {
|
||||
toast.error("Failed to delete customer");
|
||||
}
|
||||
setDeleteLoading(false);
|
||||
setDeleteOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<DropdownMenu open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
isIcon
|
||||
variant="ghost"
|
||||
dim={6}
|
||||
className={cn("rounded-full", className)}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCog} size="lg" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="text-t2">
|
||||
<DropdownMenuItem
|
||||
className="flex items-center bg-red-500 text-white"
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
await handleDelete();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between w-full gap-2">
|
||||
Delete
|
||||
{deleteLoading ? (
|
||||
<SmallSpinner />
|
||||
) : (
|
||||
<FontAwesomeIcon icon={faTrash} size="sm" />
|
||||
)}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
};
|
||||
200
frontend/src/views/customers/customer/CustomerView.tsx
Normal file
@@ -0,0 +1,200 @@
|
||||
"use client";
|
||||
|
||||
import { useAxiosSWR } from "@/services/useAxiosSwr";
|
||||
import LoadingScreen from "@/views/general/LoadingScreen";
|
||||
import { AppEnv, FeatureType, Organization } from "@autumn/shared";
|
||||
import { BreadcrumbItem } from "@nextui-org/react";
|
||||
import { Breadcrumbs } from "@nextui-org/react";
|
||||
import { CustomerContext } from "./CustomerContext";
|
||||
import { useRouter } from "next/navigation";
|
||||
import CopyButton from "@/components/general/CopyButton";
|
||||
import { CustomerToolbar } from "./CustomerToolbar";
|
||||
|
||||
import { CustomToaster } from "@/components/general/CustomToaster";
|
||||
import AddProduct from "./add-product/NewProductDropdown";
|
||||
import {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHead,
|
||||
TableCell,
|
||||
} from "@/components/ui/table";
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faSquareUpRight } from "@fortawesome/pro-duotone-svg-icons";
|
||||
import { CustomerProductList } from "./CustomerProductList";
|
||||
import { formatUnixToDateTime } from "@/utils/formatUtils/formatDateUtils";
|
||||
import { ManageEntitlements } from "./entitlements/ManageEntitlements";
|
||||
import { CustomerEntitlementsList } from "./entitlements/CustomerEntitlementsList";
|
||||
import { navigateTo } from "@/utils/genUtils";
|
||||
|
||||
export default function CustomerView({
|
||||
customer_id,
|
||||
env,
|
||||
}: {
|
||||
customer_id: string;
|
||||
env: AppEnv;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const { data, isLoading, error } = useAxiosSWR({
|
||||
url: `/customers/${customer_id}/data`,
|
||||
env,
|
||||
});
|
||||
|
||||
if (isLoading) return <LoadingScreen />;
|
||||
const { customer, products, invoices } = data;
|
||||
|
||||
return (
|
||||
<CustomerContext.Provider value={{ customer, products, env }}>
|
||||
<CustomToaster />
|
||||
<div className="flex flex-col gap-1">
|
||||
<Breadcrumbs className="text-t3">
|
||||
<BreadcrumbItem
|
||||
onClick={() => navigateTo("/customers", router, env)}
|
||||
size="sm"
|
||||
>
|
||||
Customers
|
||||
</BreadcrumbItem>
|
||||
<BreadcrumbItem size="sm">{customer.name}</BreadcrumbItem>
|
||||
</Breadcrumbs>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex gap-2">
|
||||
<h2 className="text-lg text-t1 font-medium">{customer.name}</h2>
|
||||
</div>
|
||||
<CustomerToolbar customer={customer} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between gap-4">
|
||||
{/* main content */}
|
||||
<div className="flex flex-col gap-4 text-t2 text-sm w-full">
|
||||
<p className="text-t2 font-medium text-md">Products</p>
|
||||
<div className="flex flex-col gap-1">
|
||||
<CustomerProductList customer={customer} products={products} />
|
||||
<AddProduct />
|
||||
</div>
|
||||
<p className="text-t2 font-medium text-md">Entitlements</p>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Tabs defaultValue="metered">
|
||||
<TabsList className="bg-transparent">
|
||||
<TabsTrigger
|
||||
value="metered"
|
||||
className="text-t2 text-xs font-normal"
|
||||
>
|
||||
Metered Features
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="boolean"
|
||||
className="text-t2 text-xs font-normal"
|
||||
>
|
||||
Boolean Features
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="metered">
|
||||
<CustomerEntitlementsList
|
||||
customer={{
|
||||
...customer,
|
||||
entitlements: customer.entitlements.filter(
|
||||
(cusEnt: any) => {
|
||||
const featureType = cusEnt.feature.type;
|
||||
return (
|
||||
featureType === FeatureType.Metered ||
|
||||
featureType === FeatureType.CreditSystem
|
||||
);
|
||||
}
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent value="boolean">
|
||||
<CustomerEntitlementsList
|
||||
customer={{
|
||||
...customer,
|
||||
entitlements: customer.entitlements.filter(
|
||||
(cusEnt: any) => {
|
||||
const featureType = cusEnt.feature.type;
|
||||
return featureType === FeatureType.Boolean;
|
||||
}
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<ManageEntitlements />
|
||||
</div>
|
||||
|
||||
<p className="text-t2 font-medium text-md">Invoices</p>
|
||||
<Table className="p-2">
|
||||
<TableHeader>
|
||||
<TableRow className="bg-white">
|
||||
<TableHead className="w-[150px]">Products</TableHead>
|
||||
<TableHead className="">URL</TableHead>
|
||||
<TableHead className="">Created At</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{invoices.map((invoice) => (
|
||||
<TableRow key={invoice.id}>
|
||||
<TableCell>
|
||||
{invoice.product_ids
|
||||
.map((p: string) => {
|
||||
return products.find((product) => product.id === p)
|
||||
?.name;
|
||||
})
|
||||
.join(", ")}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-[400px] truncate">
|
||||
<a
|
||||
href={invoice.processor.hosted_invoice_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center gap-2 text-lime-500"
|
||||
>
|
||||
View Invoice
|
||||
<FontAwesomeIcon icon={faSquareUpRight} />
|
||||
</a>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{formatUnixToDateTime(invoice.created_at).date}
|
||||
<span className="text-t3">
|
||||
{" "}
|
||||
{formatUnixToDateTime(invoice.created_at).time}{" "}
|
||||
</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
{/* customer details */}
|
||||
<div className="flex flex-col gap-4 text-t2 text-sm w-full max-w-[400px] h-fit">
|
||||
<h2 className="text-t2 font-medium text-md">Customer Details</h2>
|
||||
|
||||
<div className="grid grid-cols-[auto_1fr] gap-y-3 gap-x-4 w-full truncate items-center rounded-md px-4">
|
||||
<p className="text-t3 text-xs font-medium">Name</p>
|
||||
<p>{customer.name}</p>
|
||||
|
||||
<p className="text-t3 text-xs font-medium">ID</p>
|
||||
<p className="flex items-center gap-1 font-mono">
|
||||
{customer.id} <CopyButton text={customer.id} />
|
||||
</p>
|
||||
|
||||
<p className="text-t3 text-xs font-medium">Email</p>
|
||||
<p className="border border-blue-500 text-blue-500 rounded-md px-2 py-0.5 w-fit">
|
||||
{customer.email}
|
||||
</p>
|
||||
|
||||
<p className="text-t3 text-xs font-medium">Products</p>
|
||||
<p>
|
||||
{customer.products
|
||||
.map(
|
||||
(p) => products.find((prod) => prod.id === p.product_id)?.name
|
||||
)
|
||||
.join(", ")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CustomerContext.Provider>
|
||||
);
|
||||
}
|
||||