From a2cd4e1b561f43170469610ad4465ecd0217da5f Mon Sep 17 00:00:00 2001 From: DevMirza <53424436+Zaid-maker@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:09:17 +0000 Subject: [PATCH 1/7] empty From 5b644251ffd45b47360c78b477f87dbafbe1f4d2 Mon Sep 17 00:00:00 2001 From: DevMirza <53424436+Zaid-maker@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:27:11 +0000 Subject: [PATCH 2/7] add creatEvent --- app/(root)/events/create/page.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/(root)/events/create/page.tsx diff --git a/app/(root)/events/create/page.tsx b/app/(root)/events/create/page.tsx new file mode 100644 index 0000000..a6a9482 --- /dev/null +++ b/app/(root)/events/create/page.tsx @@ -0,0 +1,25 @@ +import { auth } from "@clerk/nextjs"; +import React from "react"; + +const CreateEvent = () => { + const { sessionClaims } = auth(); + + const userId = sessionClaims?.userId as string; + + return ( + <> +
+

+ Create Event +

+
+ +
+ {/* */} + EventForm +
+ + ); +}; + +export default CreateEvent; From 7103d732eae11acd08c97d4858f0f932b38390a7 Mon Sep 17 00:00:00 2001 From: DevMirza <53424436+Zaid-maker@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:30:44 +0000 Subject: [PATCH 3/7] add EventForm component --- app/(root)/events/create/page.tsx | 4 ++-- components/shared/EventForm.tsx | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 components/shared/EventForm.tsx diff --git a/app/(root)/events/create/page.tsx b/app/(root)/events/create/page.tsx index a6a9482..688b327 100644 --- a/app/(root)/events/create/page.tsx +++ b/app/(root)/events/create/page.tsx @@ -1,3 +1,4 @@ +import EventForm from "@/components/shared/EventForm"; import { auth } from "@clerk/nextjs"; import React from "react"; @@ -15,8 +16,7 @@ const CreateEvent = () => {
- {/* */} - EventForm +
); diff --git a/components/shared/EventForm.tsx b/components/shared/EventForm.tsx new file mode 100644 index 0000000..68f4bd5 --- /dev/null +++ b/components/shared/EventForm.tsx @@ -0,0 +1,17 @@ +"use client"; + +import { IEvent } from "@/lib/database/models/event.model"; +import React from "react"; + +type EventFormProps = { + userId: string; + type: "Create" | "Update"; + event?: IEvent; + eventId?: string; +}; + +const EventForm = ({}: EventFormProps) => { + return
EventForm
; +}; + +export default EventForm; From aaca12352cd1b3b85fd577837ad3a2df224c4268 Mon Sep 17 00:00:00 2001 From: DevMirza <53424436+Zaid-maker@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:40:28 +0000 Subject: [PATCH 4/7] UpdateEvent page --- app/(root)/events/create/[id]/update/page.tsx | 37 +++++++++++++++++++ components/shared/EventForm.tsx | 4 +- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 app/(root)/events/create/[id]/update/page.tsx diff --git a/app/(root)/events/create/[id]/update/page.tsx b/app/(root)/events/create/[id]/update/page.tsx new file mode 100644 index 0000000..a36d3de --- /dev/null +++ b/app/(root)/events/create/[id]/update/page.tsx @@ -0,0 +1,37 @@ +import EventForm from "@/components/shared/EventForm"; +import { getEventById } from "@/lib/actions/event.actions"; +import { auth } from "@clerk/nextjs"; + +type UpdateEventProps = { + params: { + id: string; + }; +}; + +const UpdateEvent = async ({ params: { id } }: UpdateEventProps) => { + const { sessionClaims } = auth(); + + const userId = sessionClaims?.userId as string; + const event = await getEventById(id); + + return ( + <> +
+

+ Update Event +

+
+ +
+ +
+ + ); +}; + +export default UpdateEvent; diff --git a/components/shared/EventForm.tsx b/components/shared/EventForm.tsx index 68f4bd5..455e419 100644 --- a/components/shared/EventForm.tsx +++ b/components/shared/EventForm.tsx @@ -10,8 +10,8 @@ type EventFormProps = { eventId?: string; }; -const EventForm = ({}: EventFormProps) => { - return
EventForm
; +const EventForm = ({ type }: EventFormProps) => { + return
EventForm {type}
; }; export default EventForm; From 868e09f96ea79e0aed5d1e81a1cf427042fc66b4 Mon Sep 17 00:00:00 2001 From: DevMirza <53424436+Zaid-maker@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:44:49 +0000 Subject: [PATCH 5/7] fix --- app/(root)/events/[id]/page.tsx | 7 +++++++ app/(root)/events/{create => }/[id]/update/page.tsx | 0 2 files changed, 7 insertions(+) create mode 100644 app/(root)/events/[id]/page.tsx rename app/(root)/events/{create => }/[id]/update/page.tsx (100%) diff --git a/app/(root)/events/[id]/page.tsx b/app/(root)/events/[id]/page.tsx new file mode 100644 index 0000000..012915b --- /dev/null +++ b/app/(root)/events/[id]/page.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +const EventDetails = () => { + return
EventDetails
; +}; + +export default EventDetails; diff --git a/app/(root)/events/create/[id]/update/page.tsx b/app/(root)/events/[id]/update/page.tsx similarity index 100% rename from app/(root)/events/create/[id]/update/page.tsx rename to app/(root)/events/[id]/update/page.tsx From ec3ec66d040a532d7986ca98c5edf0ab232411eb Mon Sep 17 00:00:00 2001 From: DevMirza <53424436+Zaid-maker@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:17:48 +0000 Subject: [PATCH 6/7] add form component --- components/ui/form.tsx | 177 ++++++++++++++++++++++++++++++++++++++++ components/ui/label.tsx | 26 ++++++ package-lock.json | 59 +++++++++++++- package.json | 6 +- 4 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 components/ui/form.tsx create mode 100644 components/ui/label.tsx diff --git a/components/ui/form.tsx b/components/ui/form.tsx new file mode 100644 index 0000000..497718a --- /dev/null +++ b/components/ui/form.tsx @@ -0,0 +1,177 @@ +import * as React from "react"; +import * as LabelPrimitive from "@radix-ui/react-label"; +import { Slot } from "@radix-ui/react-slot"; +import { + Controller, + ControllerProps, + FieldPath, + FieldValues, + FormProvider, + useFormContext, +} from "react-hook-form"; + +import { cn } from "@/lib/utils"; +import { Label } from "@/components/ui/label"; + +const Form = FormProvider; + +type FormFieldContextValue< + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath, +> = { + name: TName; +}; + +const FormFieldContext = React.createContext( + {} as FormFieldContextValue, +); + +const FormField = < + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath, +>({ + ...props +}: ControllerProps) => { + return ( + + + + ); +}; + +const useFormField = () => { + const fieldContext = React.useContext(FormFieldContext); + const itemContext = React.useContext(FormItemContext); + const { getFieldState, formState } = useFormContext(); + + const fieldState = getFieldState(fieldContext.name, formState); + + if (!fieldContext) { + throw new Error("useFormField should be used within "); + } + + const { id } = itemContext; + + return { + id, + name: fieldContext.name, + formItemId: `${id}-form-item`, + formDescriptionId: `${id}-form-item-description`, + formMessageId: `${id}-form-item-message`, + ...fieldState, + }; +}; + +type FormItemContextValue = { + id: string; +}; + +const FormItemContext = React.createContext( + {} as FormItemContextValue, +); + +const FormItem = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => { + const id = React.useId(); + + return ( + +
+ + ); +}); +FormItem.displayName = "FormItem"; + +const FormLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + const { error, formItemId } = useFormField(); + + return ( +