diff --git a/apps/web/package.json b/apps/web/package.json index fd4faa0c1..3f485d9bd 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -42,6 +42,7 @@ "react-hotkeys-hook": "^4.4.1", "react-icons": "^4.11.0", "react-rnd": "^10.4.1", + "remeda": "^1.27.1", "sharp": "0.33.1", "ts-pattern": "^5.0.5", "typescript": "5.2.2", diff --git a/apps/web/src/app/(dashboard)/admin/banner/banner-form.tsx b/apps/web/src/app/(dashboard)/admin/banner/banner-form.tsx deleted file mode 100644 index ce7e3e181..000000000 --- a/apps/web/src/app/(dashboard)/admin/banner/banner-form.tsx +++ /dev/null @@ -1,119 +0,0 @@ -'use client'; - -import { useRouter } from 'next/navigation'; - -import { zodResolver } from '@hookform/resolvers/zod'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; - -import { TRPCClientError } from '@documenso/trpc/client'; -import { trpc as trpcReact } from '@documenso/trpc/react'; -import { Button } from '@documenso/ui/primitives/button'; -import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@documenso/ui/primitives/form/form'; -import { Switch } from '@documenso/ui/primitives/switch'; -import { Textarea } from '@documenso/ui/primitives/textarea'; -import { useToast } from '@documenso/ui/primitives/use-toast'; - -const ZBannerSchema = z.object({ - text: z.string().optional(), - show: z.boolean().optional(), -}); - -type TBannerSchema = z.infer; - -export function BannerForm({ show, text }: TBannerSchema) { - const router = useRouter(); - const { toast } = useToast(); - - const form = useForm({ - resolver: zodResolver(ZBannerSchema), - defaultValues: { - show, - text, - }, - }); - - const { mutateAsync: updateBanner, isLoading: isUpdatingBanner } = - trpcReact.banner.updateBanner.useMutation(); - - const onBannerUpdate = async ({ show, text }: TBannerSchema) => { - try { - await updateBanner({ - show, - text, - }); - - toast({ - title: 'Banner Updated', - description: 'Your banner has been updated successfully.', - duration: 5000, - }); - - router.refresh(); - } catch (err) { - if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') { - toast({ - title: 'An error occurred', - description: err.message, - variant: 'destructive', - }); - } else { - toast({ - title: 'An unknown error occurred', - variant: 'destructive', - description: - 'We encountered an unknown error while attempting to reset your password. Please try again later.', - }); - } - } - }; - - return ( -
- - ( - -
- Show Banner - Show a banner to the users by the admin -
- - - -
- )} - /> - - ( - - Banner Text - -