diff --git a/src/app/auth/activate/resend/page.tsx b/src/app/auth/activate/resend/page.tsx index d7b801d..3c42068 100644 --- a/src/app/auth/activate/resend/page.tsx +++ b/src/app/auth/activate/resend/page.tsx @@ -56,12 +56,9 @@ const Page = () => { // return ( <div className="max-w-[500px] w-[400px] absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 border py-9 px-4 rounded-2xl"> - <h1 className="text-xl font-semibold text-center">Reset</h1> + <h1 className="text-xl font-semibold text-center">Resend Email</h1> <Form {...form}> - <form - onSubmit={form.handleSubmit(onSubmit)} - className="space-y-8" - > + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> <FormField control={form.control} name="email" diff --git a/src/app/auth/password-reset-confirm/[uid]/[token]/page.tsx b/src/app/auth/password-reset-confirm/[uid]/[token]/page.tsx index 91fbc4e..ca8d474 100644 --- a/src/app/auth/password-reset-confirm/[uid]/[token]/page.tsx +++ b/src/app/auth/password-reset-confirm/[uid]/[token]/page.tsx @@ -79,7 +79,7 @@ const ResetPasswordPage = ({ params }: { params: Params }) => { return ( <div className="max-w-[500px] w-[400px] absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 border py-9 px-4 rounded-2xl"> - <h1 className="text-xl font-semibold text-center">Reset</h1> + <h1 className="text-xl font-semibold text-center">Reset Password</h1> <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> <FormField @@ -87,7 +87,7 @@ const ResetPasswordPage = ({ params }: { params: Params }) => { name="new_password" render={({ field }) => ( <FormItem> - <FormLabel className="requred">New Password</FormLabel> + <FormLabel className="required">New Password</FormLabel> <FormControl> <Input type="password" diff --git a/src/app/auth/username-reset-confirm/[uid]/[token]/page.tsx b/src/app/auth/username-reset-confirm/[uid]/[token]/page.tsx index c987b42..5fe42e4 100644 --- a/src/app/auth/username-reset-confirm/[uid]/[token]/page.tsx +++ b/src/app/auth/username-reset-confirm/[uid]/[token]/page.tsx @@ -80,7 +80,7 @@ const Page = ({ params }: { params: Params }) => { // return ( <div className="max-w-[500px] w-[400px] absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 border py-9 px-4 rounded-2xl"> - <h1 className="text-xl font-semibold text-center">Reset</h1> + <h1 className="text-xl font-semibold text-center">Reset Email</h1> <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> <FormField diff --git a/src/app/dashboard/bookmarks/page.tsx b/src/app/dashboard/bookmarks/page.tsx index ca67ef7..41b82c3 100644 --- a/src/app/dashboard/bookmarks/page.tsx +++ b/src/app/dashboard/bookmarks/page.tsx @@ -1,12 +1,12 @@ -"use client" -import React from 'react' -import { useInnovationsBookmarksListQuery } from '@/redux/features/innovations/innovationsApiSlice'; -import ProjectCard from '@/components/ui/projectcard'; +"use client"; +import React from "react"; +import { useInnovationsBookmarksListQuery } from "@/redux/features/innovations/innovationsApiSlice"; +import ProjectCard from "@/components/ui/projectcard"; const BookmarkPage = () => { const { data: bookmarksList, isLoading: bookmarkIsLoading } = useInnovationsBookmarksListQuery(null); console.log(bookmarksList); - return ( + return ( <main> <section className="flex flex-wrap mx-auto gap-4 p-4"> {bookmarkIsLoading ? ( @@ -25,7 +25,7 @@ const BookmarkPage = () => { author_last_name={user.last_name} project_title={innovation.title} project_description={innovation.description} - dashboard_banner_image_url={innovation.banner_image} + dashboard_image_url={innovation.dashboard_image} likes_count={innovation.likes_number} comments_count={innovation.comments_number} is_liked={innovation.is_liked} @@ -37,6 +37,6 @@ const BookmarkPage = () => { </section> </main> ); -} +}; -export default BookmarkPage +export default BookmarkPage; diff --git a/src/app/dashboard/innovation/[id]/page.tsx b/src/app/dashboard/innovation/[id]/page.tsx index be4a449..56d4078 100644 --- a/src/app/dashboard/innovation/[id]/page.tsx +++ b/src/app/dashboard/innovation/[id]/page.tsx @@ -173,7 +173,7 @@ const InnovationDetailPage = ({ params }: InnovationDetailPageProps) => { <div className="flex items-center justify-between mt-5 px-4 "> <div className="flex items-center gap-3"> <Avatar className="h-12 w-12"> - <AvatarImage src={innovation?.author.profile_image} /> + <AvatarImage src={innovation?.author.profile_picture} /> <AvatarFallback className="p-2"> {get_fallback_name( innovation?.author.first_name, @@ -188,21 +188,18 @@ const InnovationDetailPage = ({ params }: InnovationDetailPageProps) => { </div> <div className="flex gap-2 md:gap-4"> - { - innovation?.dashboard_link && + {innovation?.dashboard_link && ( <Link href={innovation?.dashboard_link || ""}> <Button className="rounded-full md:px-9"> Visit </Button> </Link> - } - { - innovation?.dashboard_definition && - <Link download href={innovation.dashboard_definition}> + )} + {innovation?.dashboard_definitions && ( + <Link download href={innovation.dashboard_definitions}> <Button className="rounded-full" variant={"outline"}> Download Datasets </Button> </Link> - } - + )} </div> </div> <div className="flex p-4 my-2 justify-between bg-accent"> @@ -237,12 +234,12 @@ const InnovationDetailPage = ({ params }: InnovationDetailPageProps) => { </div> </section> <section> - {innovation?.banner_image ? ( + {innovation?.dashboard_image ? ( <Image alt="Innovation Image" width={500} height={600} - src={innovation?.banner_image} + src={innovation?.dashboard_image} /> ) : ( <></> @@ -283,8 +280,13 @@ const InnovationDetailPage = ({ params }: InnovationDetailPageProps) => { <div className="flex items-center justify-between"> <div className="flex items-center gap-3"> <Avatar className="h-12 w-12"> - <AvatarImage src="https://github.com/shadcn.png" /> - <AvatarFallback className="p-2">CN</AvatarFallback> + <AvatarImage src={comment.author.profile_picture} /> + <AvatarFallback className="p-2"> + {get_fallback_name( + innovation?.author.first_name, + innovation?.author.last_name + )} + </AvatarFallback> </Avatar> <div> <p> @@ -325,7 +327,6 @@ const InnovationDetailPage = ({ params }: InnovationDetailPageProps) => { onNext={handleNext} /> </section> - </main> ); }; diff --git a/src/app/dashboard/innovation/edit/[id]/page.tsx b/src/app/dashboard/innovation/edit/[id]/page.tsx index 5d91c5d..404c5c1 100644 --- a/src/app/dashboard/innovation/edit/[id]/page.tsx +++ b/src/app/dashboard/innovation/edit/[id]/page.tsx @@ -55,10 +55,11 @@ const InnovationSchema = z.object({ }) .min(1) .max(3), - banner_image: z - .instanceof(FileListType) - .optional() - .refine((file) => file == null || file?.length == 1, "File is required."), + dashboard_type: z.string().min(1).max(3).optional(), + // banner_image: z + // .instanceof(FileListType) + // .optional() + // .refine((file) => file == null || file?.length == 1, "File is required."), //banner_image dashboard_link: z @@ -66,11 +67,12 @@ const InnovationSchema = z.object({ required_error: "Dashboard Link is required", }) .url(), + dashboard_id: z.string().url().optional(), dashboard_image: z .instanceof(FileListType) .optional() .refine((file) => file == null || file?.length == 1, "File is required."), - dashboard_definition: z + dashboard_definitions: z .instanceof(FileListType) .optional() .refine((file) => file == null || file?.length == 1, "File is required."), @@ -81,7 +83,7 @@ interface Params { id: string; } -const EditInnovationPage = ({ params }: { params: Params }) => { +const InnovationPage = ({ params }: { params: Params }) => { const id = params.id; const { @@ -94,18 +96,19 @@ const EditInnovationPage = ({ params }: { params: Params }) => { title: innovationData?.title, description: innovationData?.description, status: innovationData?.status, + dashboard_type: innovationData?.dashboard_type, dashboard_link: innovationData?.dashboard_link || "", - banner_image: undefined, + // banner_image: undefined, dashboard_image: undefined, - dashboard_definition: undefined, + dashboard_definitions: undefined, }; const form = useForm<Innovation>({ defaultValues: { ...defaultValues, - banner_image: undefined as FileList | undefined, + // banner_image: undefined as FileList | undefined, dashboard_image: undefined as FileList | undefined, - dashboard_definition: undefined as FileList | undefined, + dashboard_definitions: undefined as FileList | undefined, }, resolver: zodResolver(InnovationSchema), }); @@ -114,20 +117,24 @@ const EditInnovationPage = ({ params }: { params: Params }) => { if (innovationData) { form.reset({ ...InnovationSchema.omit({ - banner_image: true, + // banner_image: true, + dashboard_image: true, + dashboard_definitions: true, + dashboard_type: true, status: true, }).parse({ title: innovationData.title, description: innovationData.description, dashboard_link: innovationData.dashboard_link, }), - banner_image: undefined, // or set a default value if needed + // banner_image: undefined, // or set a default value if needed dashboard_image: undefined, - dashboard_definition: undefined, + dashboard_definitions: undefined, }); setTimeout(() => { - form.setValue("status",innovationData.status); + form.setValue("status", innovationData.status); + form.setValue("dashboard_type", innovationData.dashboard_type); }, 0); } }, [innovationData]); @@ -166,7 +173,7 @@ const EditInnovationPage = ({ params }: { params: Params }) => { // <RequireAuth> <div className="px-5 md:px-20"> <h1 className="font-semibold text-lg text-center my-5"> - Create a New Innovation + Edit Innovation </h1> <Form {...form}> @@ -222,17 +229,45 @@ const EditInnovationPage = ({ params }: { params: Params }) => { <FormField control={form.control} - name="banner_image" + name="dashboard_type" render={({ field }) => ( <FormItem> - <FormLabel className="required">Banner image</FormLabel> - <FileInput {...form.register("banner_image")} /> + <FormLabel>Dashboard Type</FormLabel> + <Select + onValueChange={field.onChange} + defaultValue={field.value} + > + <FormControl> + <SelectTrigger> + <SelectValue placeholder="Select innovation type" /> + </SelectTrigger> + </FormControl> + <SelectContent> + <SelectItem value="S">Superset</SelectItem> + <SelectItem value="M">Metabase</SelectItem> + <SelectItem value="P">Power BI</SelectItem> + <SelectItem value="O">Other</SelectItem> + </SelectContent> + </Select> <FormDescription></FormDescription> <FormMessage /> </FormItem> )} /> + {/* <FormField + control={form.control} + name="banner_image" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Banner image</FormLabel> + <FileInput {...form.register("banner_image")} /> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> */} + <FormField control={form.control} name="description" @@ -274,12 +309,31 @@ const EditInnovationPage = ({ params }: { params: Params }) => { )} /> + <FormField + control={form.control} + name="dashboard_id" + render={({ field }) => ( + <FormItem> + <FormLabel>Dashboard Embed id</FormLabel> + <FormControl> + <Input + placeholder="Dashboard embed id" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> + <FormField control={form.control} name="dashboard_image" render={({ field }) => ( <FormItem> - <FormLabel>Dashboard image</FormLabel> + <FormLabel className="required">Dashboard image</FormLabel> <FileInput {...form.register("dashboard_image")} /> <FormDescription></FormDescription> <FormMessage /> @@ -289,11 +343,11 @@ const EditInnovationPage = ({ params }: { params: Params }) => { <FormField control={form.control} - name="dashboard_definition" + name="dashboard_definitions" render={({ field }) => ( <FormItem> - <FormLabel>Dashboard Definition</FormLabel> - <FileInput {...form.register("dashboard_definition")} /> + <FormLabel className="required">Dashboard Definition</FormLabel> + <FileInput {...form.register("dashboard_definitions")} /> <FormDescription></FormDescription> <FormMessage /> </FormItem> @@ -310,4 +364,4 @@ const EditInnovationPage = ({ params }: { params: Params }) => { ); }; -export default EditInnovationPage; +export default InnovationPage; diff --git a/src/app/dashboard/innovation/new/page.tsx b/src/app/dashboard/innovation/new/page.tsx index a04199e..da7a7ce 100644 --- a/src/app/dashboard/innovation/new/page.tsx +++ b/src/app/dashboard/innovation/new/page.tsx @@ -5,20 +5,20 @@ import { z } from "zod"; // Import Zod import { zodResolver } from "@hookform/resolvers/zod"; import { Button } from "@/components/ui/button"; import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, - FormMessage, + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, } from "@/components/ui/form"; import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, } from "@/components/ui/select"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; @@ -34,126 +34,166 @@ const FileListType = isBrowser ? FileList : Array; //Define the schema for the form const MAX_UPLOAD_SIZE = 1024 * 1024 * 3; // 3MB const InnovationSchema = z.object({ - title: z.string({ - required_error: "Title is required", - }).min(2).max(50), - description: z.string({ - required_error: "Description is required", - }).min(2), - status: z.string({ - required_error: "Status is required", - }).min(1).max(3), - banner_image: z - .instanceof(FileListType) - .optional() - .refine((file) => file == null || file?.length == 1, "File is required."), - - //banner_image - dashboard_link: z.string({ - required_error: "Dashboard Link is required", - }).url(), - dashboard_image: z - .instanceof(FileListType) - .optional() - .refine((file) => file == null || file?.length == 1, "File is required."), - dashboard_definition: z - .instanceof(FileListType) - .optional() - .refine((file) => file == null || file?.length == 1, "File is required."), + title: z + .string({ + required_error: "Title is required", + }) + .min(2) + .max(50), + description: z + .string({ + required_error: "Description is required", + }) + .min(2), + status: z + .string({ + required_error: "Status is required", + }) + .min(1) + .max(3), + dashboard_type: z.string().min(1).max(3).optional(), + // banner_image: z + // .instanceof(FileListType) + // .optional() + // .refine((file) => file == null || file?.length == 1, "File is required."), + + //banner_image + dashboard_link: z + .string({ + required_error: "Dashboard Link is required", + }) + .url(), + dashboard_id: z.string().url().optional(), + dashboard_image: z + .instanceof(FileListType) + .optional() + .refine((file) => file == null || file?.length == 1, "File is required."), + dashboard_definitions: z + .instanceof(FileListType) + .optional() + .refine((file) => file == null || file?.length == 1, "File is required."), }); type Innovation = z.infer<typeof InnovationSchema>; -const CreateInnovationPage = () => { - const router = useRouter(); - - const form = useForm<Innovation>({ - resolver: zodResolver(InnovationSchema), - }); - - const [createInovation, { isLoading }] = useInnovationsCreateMutation(); - - //initialize toast - const { toast } = useToast(); - - //Function that handles submision of validated data - const onSubmit = async (data: Innovation) => { - // Submit the data to your API or perform any other action - createInovation(data) - .unwrap() - .then((response) => { - // toast created successfully - toast({ - title: "Innovation Created successfully", - description: "redirecting you to the home page", - }); - form.reset(); - router.push("/dashboard"); - console.log(response); - }) - .catch((error) => { - console.log(error); - }); - }; - - return ( - // <RequireAuth> - <div className="px-5 md:px-20"> - <h1 className="font-semibold text-lg text-center my-5"> - Create a New Innovation - </h1> - - <Form {...form}> - <form - onSubmit={form.handleSubmit(onSubmit)} - className="space-y-8" - encType="multipart/form-data" - > - <FormField - control={form.control} - name="title" - render={({ field }) => ( - <FormItem> - <FormLabel className="required">Title</FormLabel> - <FormControl> - <Input - placeholder="Innovation Title" - {...field} - value={field.value || ""} - /> - </FormControl> - <FormDescription></FormDescription> - <FormMessage /> - </FormItem> - )} - /> +const InnovationPage = () => { + const router = useRouter(); - <FormField - control={form.control} - name="status" - render={({ field }) => ( - <FormItem> - <FormLabel className="required">Status</FormLabel> - <Select - onValueChange={field.onChange} - defaultValue={field.value} - > - <FormControl> - <SelectTrigger> - <SelectValue placeholder="Select innovation status" /> - </SelectTrigger> - </FormControl> - <SelectContent> - <SelectItem value="P">Published</SelectItem> - <SelectItem value="D">Draft</SelectItem> - </SelectContent> - </Select> - <FormDescription></FormDescription> - <FormMessage /> - </FormItem> - )} - /> + const form = useForm<Innovation>({ + resolver: zodResolver(InnovationSchema), + }); + + const [createInovation, { isLoading }] = useInnovationsCreateMutation(); + + //initialize toast + const { toast } = useToast(); + + //Function that handles submision of validated data + const onSubmit = async (data: Innovation) => { + // Submit the data to your API or perform any other action + createInovation(data) + .unwrap() + .then((response) => { + // toast created successfully + toast({ + title: "Innovation Created successfully", + description: "redirecting you to the home page", + }); + form.reset(); + router.push("/dashboard"); + console.log(response); + }) + .catch((error) => { + console.log(error); + }); + }; + + return ( + // <RequireAuth> + <div className="px-5 md:px-20"> + <h1 className="font-semibold text-lg text-center my-5"> + Create a New Innovation + </h1> + + <Form {...form}> + <form + onSubmit={form.handleSubmit(onSubmit)} + className="space-y-8" + encType="multipart/form-data" + > + <FormField + control={form.control} + name="title" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Title</FormLabel> + <FormControl> + <Input + placeholder="Innovation Title" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> - <FormField + <FormField + control={form.control} + name="status" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Status</FormLabel> + <Select + onValueChange={field.onChange} + defaultValue={field.value} + > + <FormControl> + <SelectTrigger> + <SelectValue placeholder="Select innovation status" /> + </SelectTrigger> + </FormControl> + <SelectContent> + <SelectItem value="P">Published</SelectItem> + <SelectItem value="D">Draft</SelectItem> + </SelectContent> + </Select> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="dashboard_type" + render={({ field }) => ( + <FormItem> + <FormLabel>Dashboard Type</FormLabel> + <Select + onValueChange={field.onChange} + defaultValue={field.value} + > + <FormControl> + <SelectTrigger> + <SelectValue placeholder="Select innovation type" /> + </SelectTrigger> + </FormControl> + <SelectContent> + <SelectItem value="S">Superset</SelectItem> + <SelectItem value="M">Metabase</SelectItem> + <SelectItem value="P">Power BI</SelectItem> + <SelectItem value="O">Other</SelectItem> + </SelectContent> + </Select> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> + + {/* <FormField control={form.control} name="banner_image" render={({ field }) => ( @@ -164,83 +204,102 @@ const CreateInnovationPage = () => { <FormMessage /> </FormItem> )} - /> + /> */} - <FormField - control={form.control} - name="description" - render={({ field }) => ( - <FormItem> - <FormLabel className="required">Description</FormLabel> - <FormControl> - <Textarea - placeholder="Tell us more about the Innovation..." - {...field} - value={field.value || ""} - /> - </FormControl> - <FormDescription> - {/* You can <span>@mention</span> other users and organizations to + <FormField + control={form.control} + name="description" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Description</FormLabel> + <FormControl> + <Textarea + placeholder="Tell us more about the Innovation..." + {...field} + value={field.value || ""} + /> + </FormControl> + <FormDescription> + {/* You can <span>@mention</span> other users and organizations to link to them. */} - </FormDescription> - <FormMessage /> - </FormItem> - )} - /> + </FormDescription> + <FormMessage /> + </FormItem> + )} + /> - <FormField - control={form.control} - name="dashboard_link" - render={({ field }) => ( - <FormItem> - <FormLabel className="required">Dashboard Link</FormLabel> - <FormControl> - <Input - placeholder="Dashboard Link" - {...field} - value={field.value || ""} - /> - </FormControl> - <FormDescription></FormDescription> - <FormMessage /> - </FormItem> - )} - /> + <FormField + control={form.control} + name="dashboard_link" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Dashboard Link</FormLabel> + <FormControl> + <Input + placeholder="Dashboard Link" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> - <FormField - control={form.control} - name="dashboard_image" - render={({ field }) => ( - <FormItem> - <FormLabel>Dashboard image</FormLabel> - <FileInput {...form.register("dashboard_image")} /> - <FormDescription></FormDescription> - <FormMessage /> - </FormItem> - )} - /> + <FormField + control={form.control} + name="dashboard_id" + render={({ field }) => ( + <FormItem> + <FormLabel>Dashboard Embed id</FormLabel> + <FormControl> + <Input + placeholder="Dashboard embed id" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> - <FormField - control={form.control} - name="dashboard_definition" - render={({ field }) => ( - <FormItem> - <FormLabel>Dashboard Definition</FormLabel> - <FileInput {...form.register("dashboard_definition")} /> - <FormDescription></FormDescription> - <FormMessage /> - </FormItem> - )} - /> - - <Button size={"lg"} type="submit" disabled={isLoading}> - Create - </Button> - </form> - </Form> - </div> - // </RequireAuth> - ); + <FormField + control={form.control} + name="dashboard_image" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Dashboard image</FormLabel> + <FileInput {...form.register("dashboard_image")} /> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="dashboard_definitions" + render={({ field }) => ( + <FormItem> + <FormLabel className="required">Dashboard Definition</FormLabel> + <FileInput {...form.register("dashboard_definitions")} /> + <FormDescription></FormDescription> + <FormMessage /> + </FormItem> + )} + /> + + <Button size={"lg"} type="submit" disabled={isLoading}> + Create + </Button> + </form> + </Form> + </div> + // </RequireAuth> + ); }; -export default CreateInnovationPage; +export default InnovationPage; diff --git a/src/app/dashboard/my-profile/page.tsx b/src/app/dashboard/my-profile/page.tsx index d6ed7a3..4526036 100644 --- a/src/app/dashboard/my-profile/page.tsx +++ b/src/app/dashboard/my-profile/page.tsx @@ -74,7 +74,7 @@ const MyProfilePage = () => { // author_last_name={user.last_name} project_title={innovation.title} project_description={innovation.description} - dashboard_banner_image_url={innovation.banner_image} + dashboard_image_url={innovation.dashboard_image} likes_count={innovation.likes_number} comments_count={innovation.comments_number} is_liked={innovation.is_liked} diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 004d1d0..853deb3 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -40,7 +40,6 @@ const Home = () => { setIsClient(true); }, []); - const totalPages = Math.ceil(innovationsList?.count / ITEMS_PER_PAGE); if (error) { @@ -52,41 +51,44 @@ const Home = () => { } else { return isClient ? ( <div className="w-full"> - <SearchComponent className="mt-4" setHasSearchResults={setHasSearchResults} hasSearchResults={hasSearchResults} /> + <SearchComponent + className="mt-4" + setHasSearchResults={setHasSearchResults} + hasSearchResults={hasSearchResults} + /> {isLoading ? ( <p>Loading..</p> + ) : !hasSearchResults ? ( + <> + <section className="flex flex-wrap mx-auto gap-4 p-4"> + {innovationsList?.results.map((innovation: any) => { + return ( + <ProjectCard + key={innovation.url} + innovation_url={innovation.url} + author_avator_image_url={innovation.author.profile_picture} + author_first_name={innovation.author.first_name} + author_last_name={innovation.author.last_name} + project_title={innovation.title} + project_description={innovation.description} + dashboard_image_url={innovation.dashboard_image} + likes_count={innovation.likes_number} + comments_count={innovation.comments_number} + is_liked={innovation.is_liked} + is_bookmarked={innovation.is_bookmarked} + /> + ); + })} + </section> + <PaginationDemo + currentPage={currentPage} + totalPages={totalPages} + onPrevious={handlePrevious} + onNext={handleNext} + /> + </> ) : ( - !hasSearchResults ? ( - <> - <section className="flex flex-wrap mx-auto gap-4 p-4"> - {innovationsList?.results.map((innovation: any) => { - return ( - <ProjectCard - key={innovation.url} - innovation_url={innovation.url} - author_avator_image_url={innovation.author.profile_picture} - author_first_name={innovation.author.first_name} - author_last_name={innovation.author.last_name} - project_title={innovation.title} - project_description={innovation.description} - dashboard_banner_image_url={innovation.banner_image} - likes_count={innovation.likes_number} - comments_count={innovation.comments_number} - is_liked={innovation.is_liked} - is_bookmarked={innovation.is_bookmarked} - /> - ); - })} - </section> - <PaginationDemo - currentPage={currentPage} - totalPages={totalPages} - onPrevious={handlePrevious} - onNext={handleNext} - /> - </> - ) : - <></> + <></> )} </div> ) : ( diff --git a/src/components/SearchComponent.tsx b/src/components/SearchComponent.tsx index 75958d5..4886193 100644 --- a/src/components/SearchComponent.tsx +++ b/src/components/SearchComponent.tsx @@ -12,16 +12,18 @@ import ProjectCard from "@/components/ui/projectcard"; import { Avatar, AvatarImage } from "@/components/ui/avatar"; type SearchComponentProps = { - className?: string, - setHasSearchResults: (value: boolean) => void, - hasSearchResults: boolean -} -function SearchComponent({ className, setHasSearchResults, hasSearchResults }: SearchComponentProps) { - + className?: string; + setHasSearchResults: (value: boolean) => void; + hasSearchResults: boolean; +}; +function SearchComponent({ + className, + setHasSearchResults, + hasSearchResults, +}: SearchComponentProps) { const [searchTerm, setSearchTerm] = useState(""); const [searchClicked, setSearchClicked] = useState(false); - const { data: innovationsResults, isLoading: isLoadingInnovations } = useSearchInnovationsQuery(searchTerm, { skip: !searchClicked }); // const { data: profilesResults, isLoading: isLoadingProfiles } = @@ -36,18 +38,17 @@ function SearchComponent({ className, setHasSearchResults, hasSearchResults }: S }; useEffect(() => { - if ((searchTerm.length > 0 && searchClicked) || - (innovationsResults && innovationsResults.innovations.length > 0)) { - + if ( + (searchTerm.length > 0 && searchClicked) || + (innovationsResults && innovationsResults.innovations.length > 0) + ) { setHasSearchResults(true); } if (searchTerm.length === 0) { setHasSearchResults(false); } - }, [innovationsResults, searchTerm]); - // console.log(innovationsResults) if (isLoadingInnovations) { return <p>Loading...</p>; @@ -77,29 +78,31 @@ function SearchComponent({ className, setHasSearchResults, hasSearchResults }: S </form> <div className="flex gap-2 flex-col max-w-full flex-wrap"> - {hasSearchResults && + {hasSearchResults && ( <> <p className="text-center">Innovation search results</p> <section className="flex flex-wrap mx-auto gap-4 p-4"> - {innovationsResults?.innovations.map((innovation: TInnovation) => ( - <ProjectCard - key={innovation.url} - innovation_url={innovation.url} - author_avator_image_url={innovation.author.profile_image} - author_first_name={innovation.author.first_name} - author_last_name={innovation.author.last_name} - project_title={innovation.title} - project_description={innovation.description} - dashboard_banner_image_url={innovation.banner_image} - likes_count={innovation.likes_number} - comments_count={innovation.comments_number} - is_liked={innovation.is_liked} - is_bookmarked={innovation.is_bookmarked} - /> - ))} + {innovationsResults?.innovations.map( + (innovation: TInnovation) => ( + <ProjectCard + key={innovation.url} + innovation_url={innovation.url} + author_avator_image_url={innovation.author.profile_picture} + author_first_name={innovation.author.first_name} + author_last_name={innovation.author.last_name} + project_title={innovation.title} + project_description={innovation.description} + dashboard_image_url={innovation.dashboard_image} + likes_count={innovation.likes_number} + comments_count={innovation.comments_number} + is_liked={innovation.is_liked} + is_bookmarked={innovation.is_bookmarked} + /> + ) + )} </section> </> - } + )} </div> {/* <h2>Profiles</h2> */} {/* <div className=""> diff --git a/src/components/ui/projectcard.tsx b/src/components/ui/projectcard.tsx index f867b1a..bc5f83f 100644 --- a/src/components/ui/projectcard.tsx +++ b/src/components/ui/projectcard.tsx @@ -55,7 +55,12 @@ import { Trash2, Copy, } from "lucide-react"; -import { useBookmarkInnovation, useLikeInnovation, useUnbookmarkInnovation, useUnlikeInnovation } from "@/lib/hooks"; +import { + useBookmarkInnovation, + useLikeInnovation, + useUnbookmarkInnovation, + useUnlikeInnovation, +} from "@/lib/hooks"; import { toast } from "./use-toast"; import { useInnovationsDeleteMutation, @@ -75,7 +80,7 @@ interface CardProps { author_last_name?: string; project_title: string; project_description: string; - dashboard_banner_image_url: string; + dashboard_image_url: string; likes_count: number; comments_count: number; is_liked: boolean; @@ -89,7 +94,7 @@ const ProjectCard = ({ author_last_name, project_title, project_description, - dashboard_banner_image_url, + dashboard_image_url, likes_count, comments_count, is_liked = false, @@ -97,7 +102,6 @@ const ProjectCard = ({ }: CardProps) => { const innovationId = extractIdFromUrl(innovation_url) as string; - const handleLike = useLikeInnovation(innovationId); const handleUnlike = useUnlikeInnovation(innovationId); const handleBookmark = useBookmarkInnovation(innovationId); @@ -115,7 +119,7 @@ const ProjectCard = ({ toast({ title: "Link copied to clipboard", }); - } + }; const handleCloseShareDialog = () => { setShowShareDialog(false); @@ -132,7 +136,6 @@ const ProjectCard = ({ //initializing the delete mutation const [deleteInnovation, { isLoading }] = useInnovationsDeleteMutation(); - const handleConfirmDelete = () => { // Perform delete operation here console.log("Project deleted"); @@ -158,11 +161,10 @@ const ProjectCard = ({ const router = useRouter(); const handleEditClick = () => { const innovationId = extractIdFromUrl(innovation_url); - return router.push(`/dashboard/new/${innovationId}`); + return router.push(`/dashboard/innovation/edit/${innovationId}`); }; - const innovationDetailURL = `http://localhost:3000/dashboard/innovation/${innovationId}` - + const innovationDetailURL = `http://localhost:3000/dashboard/innovation/${innovationId}`; return ( <Card className="max-w-[500px]"> @@ -194,9 +196,7 @@ const ProjectCard = ({ <DropdownMenuItem onSelect={handleEditClick}> <SquarePen className="mr-2 h-4 w-4" /> - <Link - href={`/dashboard/innovation/edit/${innovationId}`} - > + <Link href={`/dashboard/innovation/edit/${innovationId}`}> Edit </Link> </DropdownMenuItem> @@ -276,7 +276,7 @@ const ProjectCard = ({ <div className="flex flex-col justify-between gap-5"> <div className="flex-1"> <Image - loader={() => dashboard_banner_image_url} + loader={() => dashboard_image_url} src="/Image Icon.png" width={450} height={150} diff --git a/src/lib/types.ts b/src/lib/types.ts index 7dd2165..0865e9e 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,28 +1,30 @@ // Definition of the types used in the application interface TInnovation { - url: string; - author: { - id: string; - email: string; - profile_image: string; - username: string; - first_name: string; - last_name: string; - } - title: string; - description: string; - dashboard_link: string; - dashboard_image: string; - dashboard_definition: string; - banner_image: string; - comments_number: number; - likes_number: number; - created_at: string; - updated_at: string; - is_liked: boolean; - is_bookmarked: boolean; - status: string; - category: string; + url: string; + author: { + id: string; + email: string; + profile_picture: string; + username: string; + first_name: string; + last_name: string; + }; + title: string; + description: string; + dashboard_link: string; + dashboard_image: string; + dashboard_definitions: string; + dashboard_id: string; + // banner_image: string; + comments_number: number; + likes_number: number; + created_at: string; + updated_at: string; + is_liked: boolean; + is_bookmarked: boolean; + status: string; + dashboard_type: string; + // category: string; } type TAuthor = { @@ -65,4 +67,4 @@ type TProfile = { superset_url: string | null; }; -export type { TInnovation, TComment, CommentResponse, TProfile }; \ No newline at end of file +export type { TInnovation, TComment, CommentResponse, TProfile }; diff --git a/src/redux/features/innovations/innovationsApiSlice.ts b/src/redux/features/innovations/innovationsApiSlice.ts index 6ddd76c..694cdd9 100644 --- a/src/redux/features/innovations/innovationsApiSlice.ts +++ b/src/redux/features/innovations/innovationsApiSlice.ts @@ -19,34 +19,34 @@ const innovationsApiSlice = baseApi.injectEndpoints({ query: ({ title, description, - category, status, - banner_image, + // banner_image, dashboard_link, + dashboard_type, dashboard_image, - dashboard_definition, + dashboard_definitions, }) => { const formData = new FormData(); formData.append("title", title); formData.append("description", description); - formData.append("category", category); formData.append("status", status); formData.append("dashboard_link", dashboard_link); + formData.append("dashboard_type", dashboard_type); - if (banner_image instanceof FileList) { - formData.append("banner_image", banner_image[0]); - } else if (banner_image instanceof File) { - formData.append("banner_image", banner_image); - } + // if (banner_image instanceof FileList) { + // formData.append("banner_image", banner_image[0]); + // } else if (banner_image instanceof File) { + // formData.append("banner_image", banner_image); + // } if (dashboard_image instanceof FileList) { formData.append("dashboard_image", dashboard_image[0]); } else if (dashboard_image instanceof File) { formData.append("dashboard_image", dashboard_image); } - if (dashboard_definition instanceof FileList) { - formData.append("dashboard_definition", dashboard_definition[0]); - } else if (dashboard_definition instanceof File) { - formData.append("dashboard_definition", dashboard_definition); + if (dashboard_definitions instanceof FileList) { + formData.append("dashboard_definitions", dashboard_definitions[0]); + } else if (dashboard_definitions instanceof File) { + formData.append("dashboard_definitions", dashboard_definitions); } return { @@ -87,31 +87,33 @@ const innovationsApiSlice = baseApi.injectEndpoints({ title, description, status, - banner_image, + dashboard_type, + // banner_image, dashboard_link, dashboard_image, - dashboard_definition, + dashboard_definitions, }) => { const formData = new FormData(); formData.append("title", title); formData.append("description", description); formData.append("status", status); formData.append("dashboard_link", dashboard_link); + formData.append("dashboard_type", dashboard_type); - if (banner_image instanceof FileList) { - formData.append("banner_image", banner_image[0]); - } else if (banner_image instanceof File) { - formData.append("banner_image", banner_image); - } + // if (banner_image instanceof FileList) { + // formData.append("banner_image", banner_image[0]); + // } else if (banner_image instanceof File) { + // formData.append("banner_image", banner_image); + // } if (dashboard_image instanceof FileList) { formData.append("dashboard_image", dashboard_image[0]); } else if (dashboard_image instanceof File) { formData.append("dashboard_image", dashboard_image); } - if (dashboard_definition instanceof FileList) { - formData.append("dashboard_definition", dashboard_definition[0]); - } else if (dashboard_definition instanceof File) { - formData.append("dashboard_definition", dashboard_definition); + if (dashboard_definitions instanceof FileList) { + formData.append("dashboard_definitions", dashboard_definitions[0]); + } else if (dashboard_definitions instanceof File) { + formData.append("dashboard_definitions", dashboard_definitions); } return {