refactor: remove yearly billing interval, keep only one_time and monthly
This commit is contained in:
@@ -37,10 +37,6 @@ async function CategoryDataWrapper() {
|
||||
|
||||
async function CreateCategoryAction() {
|
||||
return (
|
||||
<CategoryDialog>
|
||||
<button className="inline-flex items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50">
|
||||
<Plus className="mr-2 h-4 w-4" /> Kategorie hinzufügen
|
||||
</button>
|
||||
</CategoryDialog>
|
||||
<CategoryDialog />
|
||||
)
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ export default function AdminLayout({
|
||||
<ShoppingCart className="w-5 h-5" />
|
||||
Bestellungen
|
||||
</Link>
|
||||
<Link href="/admin/users" className="flex items-center gap-3 px-3 py-2 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-all">
|
||||
<Users className="w-5 h-5" />
|
||||
Benutzer
|
||||
</Link>
|
||||
<Link href="/admin/settings" className="flex items-center gap-3 px-3 py-2 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-all">
|
||||
<Settings className="w-5 h-5" />
|
||||
Einstellungen
|
||||
|
||||
@@ -13,8 +13,8 @@ export default async function AdminOrdersPage() {
|
||||
<div className="space-y-6">
|
||||
<div className="flex justify-between items-center">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Bestellungen & Rechnungen</h1>
|
||||
<p className="text-muted-foreground">Verwalten Sie alle Kundenbestellungen und greifen Sie auf generierte PDFs zu.</p>
|
||||
<h1 className="text-3xl font-bold tracking-tight text-white">Bestellungen & Rechnungen</h1>
|
||||
<p className="text-slate-400">Verwalten Sie alle Kundenbestellungen und greifen Sie auf generierte PDFs zu.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -43,12 +43,12 @@ async function OrdersData() {
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="border-white/10 hover:bg-transparent">
|
||||
<TableHead className="w-[100px]">ID</TableHead>
|
||||
<TableHead>Datum</TableHead>
|
||||
<TableHead>Kunde</TableHead>
|
||||
<TableHead>Betrag</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead className="text-right">Rechnung</TableHead>
|
||||
<TableHead className="w-[100px] text-slate-200">ID</TableHead>
|
||||
<TableHead className="text-slate-200">Datum</TableHead>
|
||||
<TableHead className="text-slate-200">Kunde</TableHead>
|
||||
<TableHead className="text-slate-200">Betrag</TableHead>
|
||||
<TableHead className="text-slate-200">Status</TableHead>
|
||||
<TableHead className="text-right text-slate-200">Rechnung</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -61,17 +61,17 @@ async function OrdersData() {
|
||||
) : (
|
||||
orders?.map((order) => (
|
||||
<TableRow key={order.id} className="border-white/5 hover:bg-white/5">
|
||||
<TableCell className="font-mono text-xs text-muted-foreground">
|
||||
<TableCell className="font-mono text-xs text-slate-500">
|
||||
{order.id.slice(0, 8)}...
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<TableCell className="text-slate-300">
|
||||
{new Date(order.created_at).toLocaleDateString('de-DE')}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="font-medium">{order.customer_data?.company_name || 'Privatkunde'}</div>
|
||||
<div className="text-xs text-muted-foreground">{order.customer_data?.first_name} {order.customer_data?.last_name}</div>
|
||||
<div className="font-medium text-white">{order.customer_data?.company_name || 'Privatkunde'}</div>
|
||||
<div className="text-xs text-slate-400">{order.customer_data?.first_name} {order.customer_data?.last_name}</div>
|
||||
</TableCell>
|
||||
<TableCell className="font-semibold">
|
||||
<TableCell className="font-semibold text-white">
|
||||
{new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(order.total_price)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
|
||||
@@ -9,42 +9,42 @@ export default function AdminDashboard() {
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
<Card className="glass-dark border-white/5">
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Umsatz gesamt</CardTitle>
|
||||
<CardTitle className="text-sm font-medium text-slate-300">Umsatz gesamt</CardTitle>
|
||||
<TrendingUp className="h-4 w-4 text-primary" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">€12,234.56</div>
|
||||
<p className="text-xs text-muted-foreground">+20.1% zum Vormonat</p>
|
||||
<div className="text-2xl font-bold text-white">€12,234.56</div>
|
||||
<p className="text-xs text-slate-400">+20.1% zum Vormonat</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="glass-dark border-white/5">
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Bestellungen</CardTitle>
|
||||
<CardTitle className="text-sm font-medium text-slate-300">Bestellungen</CardTitle>
|
||||
<ShoppingCart className="h-4 w-4 text-primary" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">+573</div>
|
||||
<p className="text-xs text-muted-foreground">+12% zur Vorwoche</p>
|
||||
<div className="text-2xl font-bold text-white">+573</div>
|
||||
<p className="text-xs text-slate-400">+12% zur Vorwoche</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="glass-dark border-white/5">
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Produkte</CardTitle>
|
||||
<CardTitle className="text-sm font-medium text-slate-300">Produkte</CardTitle>
|
||||
<Package className="h-4 w-4 text-primary" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">12</div>
|
||||
<p className="text-xs text-muted-foreground">+2 neue Module</p>
|
||||
<div className="text-2xl font-bold text-white">12</div>
|
||||
<p className="text-xs text-slate-400">+2 neue Module</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="glass-dark border-white/5">
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Kunden</CardTitle>
|
||||
<CardTitle className="text-sm font-medium text-slate-300">Kunden</CardTitle>
|
||||
<Users className="h-4 w-4 text-primary" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">2,450</div>
|
||||
<p className="text-xs text-muted-foreground">+180 heute</p>
|
||||
<div className="text-2xl font-bold text-white">2,450</div>
|
||||
<p className="text-xs text-slate-400">+180 heute</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
@@ -55,8 +55,8 @@ export default function AdminDashboard() {
|
||||
<CardTitle>Übersicht</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="pl-2">
|
||||
<div className="h-[200px] flex items-center justify-center text-muted-foreground">
|
||||
[Chart Platzhalter]
|
||||
<div className="h-[200px] flex items-center justify-center text-slate-400 italic">
|
||||
[Umsatz-Chart wird geladen...]
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -72,10 +72,10 @@ export default function AdminDashboard() {
|
||||
JD
|
||||
</div>
|
||||
<div className="flex-1 space-y-1">
|
||||
<p className="text-sm font-medium">John Doe</p>
|
||||
<p className="text-xs text-muted-foreground">john.doe@example.com</p>
|
||||
<p className="text-sm font-medium text-white">John Doe</p>
|
||||
<p className="text-xs text-slate-400">john.doe@example.com</p>
|
||||
</div>
|
||||
<div className="font-medium">+€450.00</div>
|
||||
<div className="font-medium text-white">+€450.00</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ export default async function AdminProductsPage() {
|
||||
<Package className="w-8 h-8 text-primary" />
|
||||
Produkte & Module
|
||||
</h2>
|
||||
<p className="text-muted-foreground">
|
||||
<p className="text-slate-300">
|
||||
Verwalte deine Hauptprodukte und deren zubuchbare Module.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
42
shop/app/admin/users/page.tsx
Normal file
42
shop/app/admin/users/page.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { getUsers } from '@/lib/actions/users'
|
||||
import { UserList } from '@/components/admin/user-list'
|
||||
import { UserDialog } from '@/components/admin/user-dialog'
|
||||
import { Users } from 'lucide-react'
|
||||
import { Suspense } from 'react'
|
||||
|
||||
export default async function AdminUsersPage() {
|
||||
return (
|
||||
<div className="flex-1 space-y-8 p-8 pt-6">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-3xl font-bold tracking-tight text-gradient flex items-center gap-3">
|
||||
<Users className="w-8 h-8 text-primary" />
|
||||
Benutzerverwaltung
|
||||
</h2>
|
||||
<p className="text-slate-400">
|
||||
Verwalten Sie Benutzerkonten, Berechtigungen und Sicherheit.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<UserDialog />
|
||||
</div>
|
||||
</div>
|
||||
<Suspense fallback={<div className="h-40 w-full animate-pulse bg-white/5 rounded-xl" />}>
|
||||
<UserDataWrapper />
|
||||
</Suspense>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function UserDataWrapper() {
|
||||
try {
|
||||
const users = await getUsers()
|
||||
return <UserList initialUsers={users} />
|
||||
} catch (error) {
|
||||
return (
|
||||
<div className="p-8 border border-destructive/50 bg-destructive/10 rounded-xl text-destructive text-center">
|
||||
Fehler beim Laden der Benutzer. Stellen Sie sicher, dass der SERVICE_ROLE_KEY korrekt konfiguriert ist.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ const productSchema = z.object({
|
||||
base_price: z.coerce.number().min(0, 'Preis darf nicht negativ sein'),
|
||||
category_id: z.string().min(1, 'Bitte wählen Sie eine Kategorie'),
|
||||
is_active: z.boolean().default(true),
|
||||
billing_interval: z.enum(['one_time', 'monthly', 'yearly']).default('monthly'),
|
||||
billing_interval: z.enum(['one_time', 'monthly']).default('monthly'),
|
||||
modules: z.array(moduleSchema).default([]),
|
||||
})
|
||||
|
||||
@@ -190,11 +190,10 @@ export function CreateProductDialog({ children, categories, product }: { childre
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-white">Abrechnungsmodell</FormLabel>
|
||||
<div className="grid grid-cols-3 gap-2 pt-1">
|
||||
<div className="grid grid-cols-2 gap-2 pt-1">
|
||||
{[
|
||||
{ value: 'one_time', label: 'Einmalig', icon: '💳' },
|
||||
{ value: 'monthly', label: 'Monatlich', icon: '🔄' },
|
||||
{ value: 'yearly', label: 'Jährlich', icon: '📅' },
|
||||
].map(opt => (
|
||||
<button
|
||||
key={opt.value}
|
||||
|
||||
@@ -62,9 +62,6 @@ export function ProductList({ initialProducts, categories }: { initialProducts:
|
||||
{product.billing_interval === 'monthly' && (
|
||||
<Badge className="text-[10px] bg-blue-500/20 text-blue-400 border border-blue-500/30 py-0 h-4">Abo/Monat</Badge>
|
||||
)}
|
||||
{product.billing_interval === 'yearly' && (
|
||||
<Badge className="text-[10px] bg-purple-500/20 text-purple-400 border border-purple-500/30 py-0 h-4">Abo/Jahr</Badge>
|
||||
)}
|
||||
{product.billing_interval === 'one_time' && (
|
||||
<Badge className="text-[10px] bg-slate-500/20 text-slate-300 border border-slate-500/30 py-0 h-4">Einmalig</Badge>
|
||||
)}
|
||||
|
||||
113
shop/components/admin/user-dialog.tsx
Normal file
113
shop/components/admin/user-dialog.tsx
Normal file
@@ -0,0 +1,113 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import * as z from 'zod'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog'
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from '@/components/ui/form'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { createUser } from '@/lib/actions/users'
|
||||
import { Plus } from 'lucide-react'
|
||||
|
||||
const userSchema = z.object({
|
||||
email: z.string().email('Ungültige E-Mail-Adresse'),
|
||||
password: z.string().min(6, 'Passwort muss mindestens 6 Zeichen lang sein').optional(),
|
||||
})
|
||||
|
||||
type UserFormValues = z.infer<typeof userSchema>
|
||||
|
||||
export function UserDialog() {
|
||||
const [open, setOpen] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
const form = useForm<UserFormValues>({
|
||||
resolver: zodResolver(userSchema) as any,
|
||||
defaultValues: {
|
||||
email: '',
|
||||
password: '',
|
||||
},
|
||||
})
|
||||
|
||||
async function onSubmit(values: UserFormValues) {
|
||||
try {
|
||||
await createUser(values)
|
||||
setOpen(false)
|
||||
form.reset()
|
||||
router.refresh()
|
||||
} catch (error) {
|
||||
console.error('Error creating user:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button className="bg-primary hover:bg-primary/90">
|
||||
<Plus className="mr-2 h-4 w-4" /> Benutzer neu anlegen
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="glass-dark border-white/10 text-white shadow-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Neuen Benutzer anlegen</DialogTitle>
|
||||
<DialogDescription className="text-slate-300">
|
||||
Geben Sie die E-Mail und optional ein Passwort für den neuen Benutzer ein.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-white">E-Mail</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="user@example.com" className="bg-white/5 border-white/10 text-white" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="password"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="text-white">Passwort (optional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" placeholder="Passwort leer lassen für Zufall" className="bg-white/5 border-white/10 text-white" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button type="submit" className="w-full bg-primary hover:bg-primary/90">
|
||||
Benutzer erstellen
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
119
shop/components/admin/user-list.tsx
Normal file
119
shop/components/admin/user-list.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { UserX, ShieldAlert, Key, Trash2, Mail } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { deleteUser, updateUserStatus, resetPassword } from '@/lib/actions/users'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
|
||||
export function UserList({ initialUsers }: { initialUsers: any[] }) {
|
||||
const router = useRouter()
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (confirm('Möchten Sie diesen Benutzer wirklich löschen?')) {
|
||||
await deleteUser(id)
|
||||
router.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleBan = async (id: string, isBanned: boolean) => {
|
||||
await updateUserStatus(id, !isBanned)
|
||||
router.refresh()
|
||||
}
|
||||
|
||||
const handleResetPassword = async (email: string) => {
|
||||
try {
|
||||
await resetPassword(email)
|
||||
alert('Password-Reset Link generiert (siehe Mailpit/Supabase Log)')
|
||||
} catch (error) {
|
||||
alert('Fehler beim Passwort-Reset')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="glass-dark border-white/10 shadow-2xl overflow-hidden">
|
||||
<CardHeader>
|
||||
<CardTitle>Benutzerverwaltung</CardTitle>
|
||||
<CardDescription className="text-slate-400">
|
||||
Hier können Sie Benutzer neu anlegen, sperren oder Passwörter zurücksetzen.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="border-white/10 hover:bg-white/5">
|
||||
<TableHead className="text-slate-200">E-Mail</TableHead>
|
||||
<TableHead className="text-slate-200">Status</TableHead>
|
||||
<TableHead className="text-slate-200">Zuletzt angemeldet</TableHead>
|
||||
<TableHead className="text-right text-slate-200">Aktionen</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{initialUsers.map((user) => {
|
||||
const isBanned = !!user.banned_until
|
||||
return (
|
||||
<TableRow key={user.id} className="border-white/5 hover:bg-white/5 transition-colors">
|
||||
<TableCell className="font-medium text-white">
|
||||
<div className="flex items-center gap-2">
|
||||
<Mail className="w-4 h-4 text-slate-500" />
|
||||
{user.email}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={isBanned ? "destructive" : "default"} className={isBanned ? "" : "bg-green-500/20 text-green-500 border-green-500/30"}>
|
||||
{isBanned ? "Gesperrt" : "Aktiv"}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-slate-400 text-sm">
|
||||
{user.last_sign_in_at ? new Date(user.last_sign_in_at).toLocaleString('de-DE') : 'Noch nie'}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-yellow-500 hover:text-yellow-400 hover:bg-yellow-500/10"
|
||||
title="Passwort zurücksetzen"
|
||||
onClick={() => handleResetPassword(user.email)}
|
||||
>
|
||||
<Key className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={`h-8 w-8 ${isBanned ? 'text-green-500 hover:text-green-400 hover:bg-green-500/10' : 'text-orange-500 hover:text-orange-400 hover:bg-orange-500/10'}`}
|
||||
title={isBanned ? "Entsperren" : "Sperren"}
|
||||
onClick={() => handleToggleBan(user.id, isBanned)}
|
||||
>
|
||||
{isBanned ? <ShieldAlert className="h-4 w-4" /> : <UserX className="h-4 w-4" />}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
title="Löschen"
|
||||
onClick={() => handleDelete(user.id)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -24,13 +24,11 @@ type CategorySelection = {
|
||||
// ─── Billing interval helpers ─────────────────────────────────────────────────
|
||||
function billingLabel(interval?: string) {
|
||||
if (interval === 'one_time') return 'einmalig'
|
||||
if (interval === 'yearly') return '/ Jahr'
|
||||
return '/ Monat'
|
||||
}
|
||||
|
||||
function billingBadgeClass(interval?: string) {
|
||||
if (interval === 'one_time') return 'bg-slate-500/20 text-slate-300 border-slate-500/30'
|
||||
if (interval === 'yearly') return 'bg-purple-500/20 text-purple-400 border-purple-500/30'
|
||||
return 'bg-blue-500/20 text-blue-400 border-blue-500/30'
|
||||
}
|
||||
|
||||
@@ -283,7 +281,7 @@ export function OrderWizard({
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-bold text-base text-white">{product.name}</span>
|
||||
<span className={`text-[10px] px-1.5 py-0.5 rounded border ${billingBadgeClass(product.billing_interval)}`}>
|
||||
{product.billing_interval === 'one_time' ? 'Einmalig' : product.billing_interval === 'yearly' ? 'Abo/Jahr' : 'Abo/Monat'}
|
||||
{product.billing_interval === 'one_time' ? 'Einmalig' : 'Abo/Monat'}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-primary font-semibold text-sm">
|
||||
|
||||
50
shop/lib/actions/users.ts
Normal file
50
shop/lib/actions/users.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
'use server'
|
||||
|
||||
import { createAdminClient } from '@/lib/supabase/admin'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
|
||||
export async function getUsers() {
|
||||
const admin = createAdminClient()
|
||||
const { data: { users }, error } = await admin.auth.admin.listUsers()
|
||||
if (error) throw error
|
||||
return users
|
||||
}
|
||||
|
||||
export async function createUser(data: { email: string; password?: string; email_confirm?: boolean }) {
|
||||
const admin = createAdminClient()
|
||||
const { data: { user }, error } = await admin.auth.admin.createUser({
|
||||
email: data.email,
|
||||
password: data.password || Math.random().toString(36).slice(-10),
|
||||
email_confirm: data.email_confirm ?? true,
|
||||
})
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/users')
|
||||
return user
|
||||
}
|
||||
|
||||
export async function deleteUser(id: string) {
|
||||
const admin = createAdminClient()
|
||||
const { error } = await admin.auth.admin.deleteUser(id)
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/users')
|
||||
}
|
||||
|
||||
export async function updateUserStatus(id: string, ban: boolean) {
|
||||
const admin = createAdminClient()
|
||||
const { error } = await admin.auth.admin.updateUserById(id, {
|
||||
ban_duration: ban ? '876000h' : '0h', // 100 years or none
|
||||
})
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/users')
|
||||
}
|
||||
|
||||
export async function resetPassword(email: string) {
|
||||
const admin = createAdminClient()
|
||||
// Generate a reset link or send email
|
||||
const { error } = await admin.auth.admin.generateLink({
|
||||
type: 'recovery',
|
||||
email,
|
||||
})
|
||||
if (error) throw error
|
||||
// Usually you'd send this link or let Supabase handle it via regular auth.resetPasswordForEmail
|
||||
}
|
||||
16
shop/lib/supabase/admin.ts
Normal file
16
shop/lib/supabase/admin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
export function createAdminClient() {
|
||||
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU'
|
||||
|
||||
return createClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
serviceRoleKey,
|
||||
{
|
||||
auth: {
|
||||
autoRefreshToken: false,
|
||||
persistSession: false
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ export type Product = {
|
||||
description?: string | null | undefined;
|
||||
base_price: number;
|
||||
is_active: boolean;
|
||||
billing_interval: 'one_time' | 'monthly' | 'yearly';
|
||||
billing_interval: 'one_time' | 'monthly';
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
category_id?: string | null;
|
||||
|
||||
1
shop/supabase/.branches/_current_branch
Normal file
1
shop/supabase/.branches/_current_branch
Normal file
@@ -0,0 +1 @@
|
||||
main
|
||||
1
shop/supabase/.temp/cli-latest
Normal file
1
shop/supabase/.temp/cli-latest
Normal file
@@ -0,0 +1 @@
|
||||
v2.95.4
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Remove yearly from the billing_interval constraint, leaving only one_time and monthly
|
||||
ALTER TABLE public.products DROP CONSTRAINT IF EXISTS products_billing_interval_check;
|
||||
ALTER TABLE public.products ADD CONSTRAINT products_billing_interval_check
|
||||
CHECK (billing_interval IN ('one_time', 'monthly'));
|
||||
|
||||
-- Update any existing yearly products to monthly
|
||||
UPDATE public.products SET billing_interval = 'monthly' WHERE billing_interval = 'yearly';
|
||||
1
shop/supabase/snippets/Untitled query 657.sql
Normal file
1
shop/supabase/snippets/Untitled query 657.sql
Normal file
@@ -0,0 +1 @@
|
||||
update auth.users set email_confirmed_at = now() where email = 'test@test.com';
|
||||
Reference in New Issue
Block a user