Next.js 15 App Router mit öffentlicher Übersicht und geschütztem Admin-Bereich zur Pflege von Datenschutzerklärungen nach Art. 12ff. DSGVO. - Oberfläche auf Basis von shadcn/ui, Inter lokal eingebunden - Prisma/SQLite, Auth.js mit Credentials-Provider und Rollen - Massenimport der Merkblätter des Amtes Leezen aus PDF - Docker-Image (standalone) und Gitea-Workflow zur Veröffentlichung Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import useSWR, { mutate } from 'swr'
|
|
import { apiClient } from '@/lib/api'
|
|
import { PrivacyPolicy } from '@/types/privacy-policy'
|
|
|
|
const POLICIES_KEY = '/api/privacy-policies'
|
|
|
|
export function usePrivacyPolicies() {
|
|
const ADMIN_POLICIES_KEY = '/api/privacy-policies?admin=true'
|
|
|
|
const { data, error, isLoading } = useSWR<PrivacyPolicy[]>(
|
|
ADMIN_POLICIES_KEY,
|
|
() => apiClient.getAllPolicies(true),
|
|
{
|
|
refreshInterval: 5000, // Refresh every 5 seconds
|
|
revalidateOnFocus: true,
|
|
revalidateOnReconnect: true,
|
|
}
|
|
)
|
|
|
|
return {
|
|
policies: data || [],
|
|
isLoading,
|
|
error,
|
|
mutate: () => mutate(ADMIN_POLICIES_KEY),
|
|
}
|
|
}
|
|
|
|
export function usePublicPrivacyPolicies() {
|
|
const { data, error, isLoading } = useSWR<PrivacyPolicy[]>(
|
|
POLICIES_KEY,
|
|
() => apiClient.getAllPolicies(),
|
|
{
|
|
refreshInterval: 10000, // Refresh every 10 seconds for public view
|
|
revalidateOnFocus: true,
|
|
revalidateOnReconnect: true,
|
|
}
|
|
)
|
|
|
|
const publicPolicies = data?.filter(policy => policy.isPublic) || []
|
|
|
|
return {
|
|
policies: publicPolicies,
|
|
isLoading,
|
|
error,
|
|
mutate: () => mutate(POLICIES_KEY),
|
|
}
|
|
}
|
|
|
|
export async function createPolicy(data: Omit<PrivacyPolicy, 'id' | 'createdAt' | 'updatedAt'>) {
|
|
try {
|
|
const newPolicy = await apiClient.createPolicy(data)
|
|
// Trigger revalidation of both admin and public policies lists
|
|
mutate('/api/privacy-policies?admin=true')
|
|
mutate(POLICIES_KEY)
|
|
return newPolicy
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
}
|
|
|
|
export async function updatePolicy(id: number, data: Omit<PrivacyPolicy, 'id' | 'createdAt' | 'updatedAt'>) {
|
|
try {
|
|
const updatedPolicy = await apiClient.updatePolicy(id, data)
|
|
// Trigger revalidation of both admin and public policies lists
|
|
mutate('/api/privacy-policies?admin=true')
|
|
mutate(POLICIES_KEY)
|
|
return updatedPolicy
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
}
|
|
|
|
export async function deletePolicy(id: number) {
|
|
try {
|
|
const result = await apiClient.deletePolicy(id)
|
|
// Trigger revalidation of both admin and public policies lists
|
|
mutate('/api/privacy-policies?admin=true')
|
|
mutate(POLICIES_KEY)
|
|
return result
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
} |