Skip to content

Commit

Permalink
feat: 388 refactor image ulopading input
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszszczecina committed Nov 26, 2024
1 parent d2cac70 commit c1a6405
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 72 deletions.
1 change: 1 addition & 0 deletions apps/web/app/assets/svgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions apps/web/app/assets/svgs/trash-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 17 additions & 16 deletions apps/web/app/components/FileUploadInput/ImageUploadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@ interface ImageUploadProps {
const ImageUploadInput = ({ field, handleImageUpload, isUploading }: ImageUploadProps) => {
return (
<div className="flex items-center justify-center flex-col gap-y-2">
<div className="w-full h-[20rem] border-solid border-2 border-gray-300 flex justify-center items-center bg-gray-100 relative cursor-pointer overflow-hidden flex-col">
<div className="w-full h-[20rem] rounded-lg border-solid border-2 border-gray-300 flex justify-center items-center bg-gray-100 relative cursor-pointer overflow-hidden flex-col">
{field.value && (
<img src={field.value} alt="Uploaded" className="w-full h-full object-cover" />
)}
<div
className={`absolute inset-0 flex flex-col items-center justify-center text-center ${
field.value ? "text-white" : ""
}`}
>
<Icon name="UploadImageIcon" />

{!field.value && (
<div>
<Icon name="UploadImageIcon" />
<div className="flex items-center justify-center mt-2">
<span className={`text-lg font-semibold text-[#7CA3DE]`}>
{field.value ? "Click to replace" : "Click to upload"}
</span>
<span className="ml-2 text-lg font-semibold">or drag and drop</span>
</div>
)}

{!field.value && (
<div className="flex items-center justify-center">
<span className="text-blue-500 text-lg font-semibold">Click to upload</span>
<span className="text-black text-lg font-semibold ml-2">or drag and drop</span>
<div
className={`text-sm w-full px-2 mt-2 ${field.value ? "text-white" : "text-gray-600"}`}
>
{field.value ? "SVG, PNG, JPG (max. to 20MB)" : "SVG, PNG, JPG or GIF (max. 800x400px)"}
</div>
)}

</div>
<input
type="file"
accept="image/*"
Expand All @@ -42,11 +48,6 @@ const ImageUploadInput = ({ field, handleImageUpload, isUploading }: ImageUpload
disabled={isUploading}
className="absolute inset-0 opacity-0 cursor-pointer"
/>
{!field.value && (
<div className="text-center mt-2 text-gray-600 text-sm w-full px-2">
SVG, PNG, JPG or GIF (max. 20MB)
</div>
)}
</div>
</div>
);
Expand Down
36 changes: 19 additions & 17 deletions apps/web/app/modules/Admin/AddCourse/AddCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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");

Expand All @@ -49,12 +48,10 @@ const AddCourse = () => {

return (
<div className="flex h-screen bg-white">
<div className="w-2/5 flex items-center justify-center">
<Card className="bg-gray-100 p-6 rounded-lg shadow-md w-4/5 h-[65rem] flex items-center justify-center">
<img src={SplashScreenImage} alt="splashScreenImage" className="rounded" />
</Card>
<div className="w-1/2 flex items-center justify-center">
<img src={SplashScreenImage} alt="splashScreenImage" className="rounded" />
</div>
<div className="w-3/5 mt-[6.5rem]">
<div className="w-1/2 mt-[1rem]">
<Button
onClick={() => navigate("/admin/courses")}
className="border-2 border-beige-500 bg-white text-blue-500 py-2 px-6 rounded"
Expand Down Expand Up @@ -162,21 +159,26 @@ const AddCourse = () => {
{watchedImageUrl && (
<Button
onClick={() => form.setValue("imageUrl", "")}
className="bg-red-500 text-white py-2 px-6 rounded mb-4"
className="bg-red-500 text-white py-2 px-6 rounded mb-4 mt-4"
>
<Icon name="TrashIcon" className="mr-2" />
Remove Thumbnail
</Button>
)}

<div className="flex space-x-5 mt-5">
<Button className="bg-white text-blue-500 border-2 rounded px-6 py-2">Cancel</Button>
<Button
type="submit"
className="bg-blue-500 text-white rounded px-6 py-2"
disabled={isFormValid || isUploading || !isDirty}
>
Proceed
</Button>
<div className="pb-5">
<div className="flex space-x-5 mt-5 mb-10">
<Button className="bg-white text-blue-500 border-2 rounded px-6 py-2">
Cancel
</Button>
<Button
type="submit"
className="bg-blue-500 text-white rounded px-6 py-2"
disabled={!isFormValid || isUploading}
>
Proceed
</Button>
</div>
</div>
</form>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ export const useAddCourseForm = () => {
defaultValues: {
title: "",
description: "",
state: "draft",
categoryId: "",
imageUrl: "",
},
});

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}`);
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -68,7 +69,7 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett

return (
<div className="w-full flex gap-4 ">
<Card className="p-6 shadow-md border border-gray-200 w-7/10 flex-grow">
<Card className="p-4 shadow-md border border-gray-200 w-7/10 flex-grow">
<CardHeader>
<h5 className="text-xl font-semibold">Basic settings</h5>
</CardHeader>
Expand All @@ -82,8 +83,8 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett
render={({ field }) => (
<FormItem>
<Label htmlFor="title" className="text-right">
<span className="text-red-500">*</span>
Course title
<span className="text-red-500 mr-1">*</span>
Title
</Label>
<FormControl>
<Input id="title" {...field} required />
Expand All @@ -98,7 +99,7 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett
render={({ field }) => (
<FormItem className="mt-5">
<Label htmlFor="description" className="text-right">
<span className="text-red-500">*</span>
<span className="text-red-500 mr-1">*</span>
Description
</Label>
<FormControl>
Expand All @@ -120,7 +121,7 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett
render={({ field }) => (
<FormItem className="flex-1 mt-5">
<Label htmlFor="categoryId" className="text-right">
<span className="text-red-500">*</span>
<span className="text-red-500 mr-1">*</span>
Category
</Label>
<Select onValueChange={field.onChange} defaultValue={field.value}>
Expand Down Expand Up @@ -167,8 +168,9 @@ const CourseSettings = ({ title, description, categoryId, imageUrl }: CourseSett
{watchedImageUrl && (
<Button
onClick={() => form.setValue("imageUrl", "")}
className="bg-red-500 text-white py-2 px-6 rounded mb-4"
className="bg-red-500 text-white py-2 px-6 rounded mb-4 mt-4"
>
<Icon name="TrashIcon" className="mr-2" />
Remove Thumbnail
</Button>
)}
Expand Down
6 changes: 3 additions & 3 deletions apps/web/app/modules/Admin/EditCourse/EditCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { NavigationTab } from "./EditCourse.types";
const Lesson = () => (
<Card className="p-6 shadow-md border border-gray-200">
<CardHeader>
<h5 className="text-xl font-semibold">Lesson</h5>
<h5 className="text-xl font-semibold">Curriculum</h5>
</CardHeader>
<CardContent>
<p>Here you can add and manage lessons for your course.</p>
Expand Down Expand Up @@ -82,8 +82,8 @@ const EditCourse = () => {
<div className="p-6">
<Card className="shadow-md border border-gray-200">
<CardHeader>
<h4 className="text-neutral-950 text-2xl font-bold leading-10 pb-1 mb-1">
Create new course
<h4 className="text-neutral-950 text-2xl font-bold leading-10 pb-1">
{course?.title || ""}
</h4>
</CardHeader>
<CardContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DefaultCoursePhoto from "~/assets/default-photo-course.svg";
import { Button } from "~/components/ui/button";
import { Card, CardContent, CardHeader } from "~/components/ui/card";
import { UserProfile } from "~/modules/Dashboard/DashboardNavigation/UserProfile";

type CourseCardPreviewProps = {
imageUrl?: string;
Expand Down Expand Up @@ -34,11 +35,12 @@ const CourseCardPreview = ({ imageUrl, title, description, category }: CourseCar
</CardHeader>
<CardContent className="flex flex-col justify-between p-3">
<h1 className="font-bold text-left break-words">{title || "Untitled"}</h1>
<UserProfile />
<div
className="description text-left break-words mt-10 line-clamp-3 text-gray-500"
className="description text-left break-words line-clamp-3 text-gray-500"
dangerouslySetInnerHTML={{ __html: description || "No description yet." }}
/>
<div className="flex justify-center w-full mt-10">
<div className="flex justify-center w-full mt-5">
<Button className="mt-4 mx-auto w-3/4">Enroll</Button>
</div>
</CardContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ type NavigationTabsProps = {
setNavigationTabState: (navigationTabState: NavigationTab) => void;
};

const TabTrigger = ({ value, children }: { value: string; children: React.ReactNode }) => (
<Tabs.Trigger
className="text-gray-700 hover:text-black text-lg px-4 py-2 data-[state=active]:border-b-2 data-[state=active]:border-black"
value={value}
>
{children}
</Tabs.Trigger>
);

const NavigationTabs = ({ setNavigationTabState }: NavigationTabsProps) => {
const handleValueChange = (value: string) => {
setNavigationTabState(value as NavigationTab);
Expand All @@ -14,30 +23,10 @@ const NavigationTabs = ({ setNavigationTabState }: NavigationTabsProps) => {
return (
<Tabs.Root className="flex flex-col" defaultValue="Settings" onValueChange={handleValueChange}>
<Tabs.List className="flex items-center gap-5 border-b border-gray-200">
<Tabs.Trigger
className="text-gray-700 hover:text-black text-lg px-4 py-2 data-[state=active]:border-b-2 data-[state=active]:border-black"
value="Settings"
>
Settings
</Tabs.Trigger>
<Tabs.Trigger
className="text-gray-700 hover:text-black text-lg px-4 py-2 data-[state=active]:border-b-2 data-[state=active]:border-black"
value="Lesson"
>
Lesson
</Tabs.Trigger>
<Tabs.Trigger
className="text-gray-700 hover:text-black text-lg px-4 py-2 data-[state=active]:border-b-2 data-[state=active]:border-black"
value="Pricing"
>
Pricing
</Tabs.Trigger>
<Tabs.Trigger
className="text-gray-700 hover:text-black text-lg px-4 py-2 data-[state=active]:border-b-2 data-[state=active]:border-black"
value="Status"
>
Status
</Tabs.Trigger>
<TabTrigger value="Settings">Settings</TabTrigger>
<TabTrigger value="Lesson">Curriculum</TabTrigger>
<TabTrigger value="Pricing">Pricing</TabTrigger>
<TabTrigger value="Status">Status</TabTrigger>
</Tabs.List>
</Tabs.Root>
);
Expand Down

0 comments on commit c1a6405

Please sign in to comment.