From c1a64051e17f5c925523d1f32fb08702c006b558 Mon Sep 17 00:00:00 2001 From: mateuszszczecina Date: Tue, 26 Nov 2024 09:06:09 +0100 Subject: [PATCH] feat: 388 refactor image ulopading input --- apps/web/app/assets/svgs/index.ts | 1 + apps/web/app/assets/svgs/trash-icon.svg | 3 ++ .../FileUploadInput/ImageUploadInput.tsx | 33 +++++++++-------- .../app/modules/Admin/AddCourse/AddCourse.tsx | 36 +++++++++--------- .../AddCourse/hooks/useAddCourseForm.tsx | 5 +-- .../validators/addCourseFormSchema.ts | 1 - .../CourseSettings/CourseSettings.tsx | 14 ++++--- .../modules/Admin/EditCourse/EditCourse.tsx | 6 +-- .../compontents/CourseCardPreview.tsx | 6 ++- .../EditCourse/compontents/NavigationTabs.tsx | 37 +++++++------------ 10 files changed, 70 insertions(+), 72 deletions(-) create mode 100644 apps/web/app/assets/svgs/trash-icon.svg diff --git a/apps/web/app/assets/svgs/index.ts b/apps/web/app/assets/svgs/index.ts index 55d89f4d..946e37ed 100644 --- a/apps/web/app/assets/svgs/index.ts +++ b/apps/web/app/assets/svgs/index.ts @@ -19,6 +19,7 @@ export { default as User } from "./user.svg?react"; export { default as Course } from "./course.svg?react"; export { default as Category } from "./category.svg?react"; export { default as UploadImageIcon } from "./upload-image.svg?react"; +export { default as TrashIcon } from "./trash-icon.svg?react"; export { default as Lesson } from "./lesson.svg?react"; export { default as LessonContent } from "./lesson-content.svg?react"; export { default as Email } from "./email.svg?react"; diff --git a/apps/web/app/assets/svgs/trash-icon.svg b/apps/web/app/assets/svgs/trash-icon.svg new file mode 100644 index 00000000..3712b71c --- /dev/null +++ b/apps/web/app/assets/svgs/trash-icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/apps/web/app/components/FileUploadInput/ImageUploadInput.tsx b/apps/web/app/components/FileUploadInput/ImageUploadInput.tsx index 2b09432d..dd9802d6 100644 --- a/apps/web/app/components/FileUploadInput/ImageUploadInput.tsx +++ b/apps/web/app/components/FileUploadInput/ImageUploadInput.tsx @@ -12,24 +12,30 @@ interface ImageUploadProps { const ImageUploadInput = ({ field, handleImageUpload, isUploading }: ImageUploadProps) => { return (
-
+
{field.value && ( Uploaded )} +
+ - {!field.value && ( -
- +
+ + {field.value ? "Click to replace" : "Click to upload"} + + or drag and drop
- )} - {!field.value && ( -
- Click to upload - or drag and drop +
+ {field.value ? "SVG, PNG, JPG (max. to 20MB)" : "SVG, PNG, JPG or GIF (max. 800x400px)"}
- )} - +
- {!field.value && ( -
- SVG, PNG, JPG or GIF (max. 20MB) -
- )}
); diff --git a/apps/web/app/modules/Admin/AddCourse/AddCourse.tsx b/apps/web/app/modules/Admin/AddCourse/AddCourse.tsx index 6732eff8..861f29c0 100644 --- a/apps/web/app/modules/Admin/AddCourse/AddCourse.tsx +++ b/apps/web/app/modules/Admin/AddCourse/AddCourse.tsx @@ -8,7 +8,6 @@ import ImageUploadInput from "~/components/FileUploadInput/ImageUploadInput"; import { Icon } from "~/components/Icon"; import Editor from "~/components/RichText/Editor"; import { Button } from "~/components/ui/button"; -import { Card } from "~/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormMessage } from "~/components/ui/form"; import { Input } from "~/components/ui/input"; import { Label } from "~/components/ui/label"; @@ -28,7 +27,7 @@ const AddCourse = () => { const { data: categories } = useCategoriesSuspense(); const [isUploading, setIsUploading] = useState(false); const { mutateAsync: uploadFile } = useUploadFile(); - const { isValid: isFormValid, isDirty } = form.formState; + const { isValid: isFormValid } = form.formState; const watchedImageUrl = form.watch("imageUrl"); const imageUrl = form.getValues("imageUrl"); @@ -49,12 +48,10 @@ const AddCourse = () => { return (
-
- - splashScreenImage - +
+ splashScreenImage
-
+
)} -
- - +
+
+ + +
diff --git a/apps/web/app/modules/Admin/AddCourse/hooks/useAddCourseForm.tsx b/apps/web/app/modules/Admin/AddCourse/hooks/useAddCourseForm.tsx index c899d764..86f5a55b 100644 --- a/apps/web/app/modules/Admin/AddCourse/hooks/useAddCourseForm.tsx +++ b/apps/web/app/modules/Admin/AddCourse/hooks/useAddCourseForm.tsx @@ -17,7 +17,6 @@ export const useAddCourseForm = () => { defaultValues: { title: "", description: "", - state: "draft", categoryId: "", imageUrl: "", }, @@ -25,10 +24,10 @@ export const useAddCourseForm = () => { const onSubmit = (values: AddCourseFormValues) => { createCourse({ - data: { ...values }, + data: { ...values, state: "draft" }, }).then(({ data }) => { queryClient.invalidateQueries({ queryKey: ALL_COURSES_QUERY_KEY }); - navigate(`/admin/courses/${data.id}`); + navigate(`/admin/beta-courses/${data.id}`); }); }; diff --git a/apps/web/app/modules/Admin/AddCourse/validators/addCourseFormSchema.ts b/apps/web/app/modules/Admin/AddCourse/validators/addCourseFormSchema.ts index 5535fc7c..8ded61a7 100644 --- a/apps/web/app/modules/Admin/AddCourse/validators/addCourseFormSchema.ts +++ b/apps/web/app/modules/Admin/AddCourse/validators/addCourseFormSchema.ts @@ -3,7 +3,6 @@ import { z } from "zod"; export const addCourseFormSchema = z.object({ title: z.string().min(2, "Title must be at least 2 characters."), description: z.string().min(2, "Description must be at least 2 characters."), - state: z.enum(["draft", "published"]), categoryId: z.string().min(1, "Category is required"), imageUrl: z.union([z.string().url("Invalid image URL"), z.string().length(0)]).optional(), }); diff --git a/apps/web/app/modules/Admin/EditCourse/CourseSettings/CourseSettings.tsx b/apps/web/app/modules/Admin/EditCourse/CourseSettings/CourseSettings.tsx index b74e2e3b..c71d2402 100644 --- a/apps/web/app/modules/Admin/EditCourse/CourseSettings/CourseSettings.tsx +++ b/apps/web/app/modules/Admin/EditCourse/CourseSettings/CourseSettings.tsx @@ -4,6 +4,7 @@ import { useCallback, useMemo, useState } from "react"; import { useUploadFile } from "~/api/mutations/admin/useUploadFile"; import { useCategoriesSuspense } from "~/api/queries/useCategories"; import ImageUploadInput from "~/components/FileUploadInput/ImageUploadInput"; +import { Icon } from "~/components/Icon"; import Editor from "~/components/RichText/Editor"; import { Button } from "~/components/ui/button"; import { Card, CardContent, CardHeader } from "~/components/ui/card"; @@ -68,7 +69,7 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett return (
- +
Basic settings
@@ -82,8 +83,8 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett render={({ field }) => ( @@ -98,7 +99,7 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett render={({ field }) => ( @@ -120,7 +121,7 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett render={({ field }) => (