diff --git a/src/app/editArea/[slug]/addClimbs/components/AddClimbsForm.tsx b/src/app/editArea/[slug]/addClimbs/components/AddClimbsForm.tsx new file mode 100644 index 000000000..562d5fc13 --- /dev/null +++ b/src/app/editArea/[slug]/addClimbs/components/AddClimbsForm.tsx @@ -0,0 +1,38 @@ +'use client' +import { useSession } from 'next-auth/react' + +import { SingleEntryForm } from 'app/editArea/[slug]/components/SingleEntryForm' +import { AREA_DESCRIPTION_FORM_VALIDATION_RULES } from '@/components/edit/EditAreaForm' +import useUpdateAreasCmd from '@/js/hooks/useUpdateAreasCmd' +import { MarkdownTextArea } from '@/components/ui/form/MarkdownTextArea' +import useUpdateClimbsCmd from '@/js/hooks/useUpdateClimbsCmd' +import { DashboardInput } from '@/components/ui/form/Input' +import { DynamicClimbInputList } from './DynamicClimbInputList' +/** + * Area description edit form + * @param param0 + * @returns + */ +export const AddClimbsForm: React.FC<{ parentAreaUuid: string }> = ({ parentAreaUuid }) => { + const session = useSession({ required: true }) + const { updateClimbCmd } = useUpdateClimbsCmd( + { + parentId: parentAreaUuid, + accessToken: session?.data?.accessToken as string + } + ) + + return ( + + title='Add climbs' + initialValues={{ climbList: [{ climbName: '' }] }} + // initialValues={{ description: initialValue }} + submitHandler={async (data) => { + console.log(data) + // await updateClimbCmd({ description }) + }} + > + + + ) +} diff --git a/src/app/editArea/[slug]/addClimbs/components/DynamicClimbInputList.tsx b/src/app/editArea/[slug]/addClimbs/components/DynamicClimbInputList.tsx new file mode 100644 index 000000000..47ed6debe --- /dev/null +++ b/src/app/editArea/[slug]/addClimbs/components/DynamicClimbInputList.tsx @@ -0,0 +1,76 @@ +import { useCallback } from 'react' +import { useFieldArray, useFormContext } from 'react-hook-form' +import { ListPlus, Minus } from '@phosphor-icons/react/dist/ssr' + +import { BaseInput } from '@/components/ui/form/Input' + +export const DynamicClimbInputList: React.FC<{ parentAreaUuid: string, name: string }> = ({ parentAreaUuid, name = 'climbList' }) => { + const { + fields, + append, + remove + } = useFieldArray({ + name + }) + + const addMoreFields = useCallback(() => { + for (let i = 0; i < 5; i++) { + append({ climbName: '' }) + } + }, [append]) + + return ( +
+
    + {fields.map((item, index) => { + return ( +
  • + + remove(removeIndex)} + /> + +
  • + ) + })} +
+ + +
+ ) +} + +const NewClimbInput: React.FC<{ parentAreaUuid: string, index: number, count: number, onRemove: (index: number) => void }> = ({ parentAreaUuid, index, count, onRemove }) => { + const formContext = useFormContext() + const inputName = `climbList[${index}].climbName` + return ( +
+
+ +
+ + {count > 1 && + } +
+
+
+ ) +} diff --git a/src/app/editArea/[slug]/addClimbs/page.tsx b/src/app/editArea/[slug]/addClimbs/page.tsx index 9b1b444f6..6e07bb193 100644 --- a/src/app/editArea/[slug]/addClimbs/page.tsx +++ b/src/app/editArea/[slug]/addClimbs/page.tsx @@ -1,10 +1,16 @@ +import { DashboardPageProps, getPageDataForEdit } from '../general/page' import { PageContainer, SectionContainer } from '../components/EditAreaContainers' +import { AddClimbsForm } from './components/AddClimbsForm' -export default function AddClimbsPage (): JSX.Element { +export default async function AddClimbsPage ({ params: { slug } }: DashboardPageProps): Promise { + const { area } = await getPageDataForEdit(slug) + const { + areaName, uuid, ancestors, pathTokens, children + } = area return ( -
Add new climbs form (TBD)
+
)