From 6935e1e81e038e1140522c3162192f569964197f Mon Sep 17 00:00:00 2001 From: Carl Malmz Date: Fri, 17 May 2024 03:46:06 +0200 Subject: [PATCH] add back working row actions --- app/components/form/date-picker.tsx | 63 +++++++ app/components/form/form.tsx | 49 ++++++ app/components/form/input.tsx | 9 + app/components/form/textarea.tsx | 9 + app/lib/actions.server.ts | 20 ++- app/lib/auth.server.ts | 2 +- app/lib/schema.server.ts | 7 +- app/lib/storage/image.ts | 25 ++- app/routes/_main.admin.$id/columns.tsx | 48 +----- app/routes/_main.admin.$id/publish-button.tsx | 14 +- app/routes/_main.admin.$id/route.tsx | 156 ++++++++++-------- app/routes/_main.admin.$id/row-actions.tsx | 64 +++++++ app/routes/_main.admin._index/columns.tsx | 81 +++++++++ .../route.tsx} | 85 +++++----- app/routes/_main.admin._index/row-actions.tsx | 61 +++++++ app/routes/api.image.$id.tsx | 28 +++- package-lock.json | 141 ++++++++-------- package.json | 11 +- vite.config.ts | 3 + 19 files changed, 626 insertions(+), 250 deletions(-) create mode 100644 app/components/form/date-picker.tsx create mode 100644 app/components/form/form.tsx create mode 100644 app/components/form/input.tsx create mode 100644 app/components/form/textarea.tsx create mode 100644 app/routes/_main.admin.$id/row-actions.tsx create mode 100644 app/routes/_main.admin._index/columns.tsx rename app/routes/{_main.admin._index.tsx => _main.admin._index/route.tsx} (52%) create mode 100644 app/routes/_main.admin._index/row-actions.tsx diff --git a/app/components/form/date-picker.tsx b/app/components/form/date-picker.tsx new file mode 100644 index 0000000..4247d4b --- /dev/null +++ b/app/components/form/date-picker.tsx @@ -0,0 +1,63 @@ +import React, { useRef, useState } from 'react'; +import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'; +import { Button } from '../ui/button'; +import { cn } from '~/lib/utils'; +import { CalendarIcon } from 'lucide-react'; +import { format } from 'date-fns'; +import { Calendar } from '../ui/calendar'; +import { sv } from 'date-fns/locale'; +import { useField } from './form'; + +interface Props + extends Omit, 'defaultValue'> { + defaultValue?: Date; +} +export function FormDatePicker({ name, defaultValue, ...props }: Props) { + const triggerRef = useRef(null); + const { id, errorId } = useField(); + const [value, setValue] = useState(defaultValue); + + return ( +
+ { + triggerRef.current?.focus(); + }} + /> + + + + + + + + +
+ ); +} diff --git a/app/components/form/form.tsx b/app/components/form/form.tsx new file mode 100644 index 0000000..8eed123 --- /dev/null +++ b/app/components/form/form.tsx @@ -0,0 +1,49 @@ +import React, { createContext, useContext, useId } from 'react'; +import { cn } from '~/lib/utils'; +import { Label } from '../ui/label'; + +const FieldContext = createContext<{ id?: string; errorId?: string }>({}); +export const useField = () => useContext(FieldContext); + +interface ErrorProps extends React.HTMLAttributes {} +export function FormError({ className, ...props }: ErrorProps) { + const { id } = useField(); + return ( +
+ ); +} + +interface LabelProps extends React.ComponentProps {} +export function FormLabel({ ...props }: LabelProps) { + const { id } = useField(); + return ; +} + +interface DescriptionProps extends React.HTMLAttributes {} +export function FormDescription({ className, ...props }: DescriptionProps) { + const { errorId } = useField(); + return ( +

+ ); +} + +export function FormField({ + className, + ...props +}: React.HTMLAttributes) { + const id = useId(); + const errorId = useId(); + return ( + +

+ + ); +} diff --git a/app/components/form/input.tsx b/app/components/form/input.tsx new file mode 100644 index 0000000..990ecc8 --- /dev/null +++ b/app/components/form/input.tsx @@ -0,0 +1,9 @@ +import { Input } from '../ui/input'; +import type { ComponentProps } from 'react'; +import { useField } from './form'; + +interface Props extends ComponentProps {} +export function FormInput({ ...props }: Props) { + const { id, errorId } = useField(); + return ; +} diff --git a/app/components/form/textarea.tsx b/app/components/form/textarea.tsx new file mode 100644 index 0000000..bdf69ff --- /dev/null +++ b/app/components/form/textarea.tsx @@ -0,0 +1,9 @@ +import { Textarea } from '~/components/ui/textarea'; +import type { ComponentProps } from 'react'; +import { useField } from './form'; + +interface Props extends ComponentProps {} +export function FormTextarea({ ...props }: Props) { + const { id, errorId } = useField(); + return