From 28b3cc9af105bd4520017605f2e7b600c16e6c87 Mon Sep 17 00:00:00 2001 From: Sam Rizvi Date: Fri, 3 Nov 2023 07:02:55 -0700 Subject: [PATCH] chore: improve validations for editing after publish - updated validations for playbook and play creation - improved form descriptions - cleaned up styles for consistency on teacher flow again Fixes #284 --- .../[courseId]/chapters/[chapterId]/page.tsx | 2 +- .../teacher/courses/[courseId]/page.tsx | 4 +-- .../learn/(dashboard)/teacher/create/page.tsx | 15 +++++++---- apps/lms/app/config/navbar-routes.tsx | 4 +-- .../teacher/chapters/chapter-access-form.tsx | 2 +- .../teacher/chapters/chapter-actions.tsx | 6 ++--- .../chapters/chapter-description-form.tsx | 23 ++++++++++++---- .../teacher/chapters/chapter-title-form.tsx | 24 ++++++++++++++--- .../teacher/chapters/chapter-video-form.tsx | 2 +- .../app/ui/learn/teacher/courses/actions.tsx | 4 +-- .../learn/teacher/courses/attachment-form.tsx | 8 +++--- .../learn/teacher/courses/category-form.tsx | 16 +++++++----- .../learn/teacher/courses/chapters-form.tsx | 23 +++++++++++----- .../teacher/courses/description-form.tsx | 26 +++++++++++++------ .../ui/learn/teacher/courses/image-form.tsx | 4 +-- .../ui/learn/teacher/courses/preview-form.tsx | 21 +++++++++------ .../ui/learn/teacher/courses/price-form.tsx | 15 +++++++---- .../ui/learn/teacher/courses/title-form.tsx | 19 ++++++++++---- apps/lms/app/ui/session-info.tsx | 4 +-- apps/lms/app/ui/user-account-nav.tsx | 2 +- packages/ui/components/mode-toggle.tsx | 4 +-- 21 files changed, 153 insertions(+), 75 deletions(-) diff --git a/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/chapters/[chapterId]/page.tsx b/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/chapters/[chapterId]/page.tsx index 5893aad..70784f2 100644 --- a/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/chapters/[chapterId]/page.tsx +++ b/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/chapters/[chapterId]/page.tsx @@ -62,7 +62,7 @@ const ChapterIdPage = async ({ href={`/learn/teacher/courses/${params.courseId}`} className="mb-6 flex items-center text-sm transition hover:opacity-75" > - + Back to playbook setup
diff --git a/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/page.tsx b/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/page.tsx index d5d6687..6d7380f 100644 --- a/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/page.tsx +++ b/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/courses/[courseId]/page.tsx @@ -57,7 +57,7 @@ const CourseIdPage = async ({ params }: { params: { courseId: string } }) => { course.preview, course.description, course.imageUrl, - course.price, + course.price !== null && course.price !== undefined, course.categoryId, course.chapters.some((chapter) => chapter.isPublished), ]; @@ -77,7 +77,7 @@ const CourseIdPage = async ({ params }: { params: { courseId: string } }) => {
-

+

Playbook setup

diff --git a/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/create/page.tsx b/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/create/page.tsx index 5b753a4..5d577f6 100644 --- a/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/create/page.tsx +++ b/apps/lms/app/(dashboard)/(learn)/learn/(dashboard)/teacher/create/page.tsx @@ -21,9 +21,14 @@ import { useForm } from 'react-hook-form'; import * as z from 'zod'; const formSchema = z.object({ - title: z.string().min(1, { - message: 'Every playbook needs a title.', - }), + title: z + .string() + .min(40, { + message: 'Ouch! The playbook title must be at least 40 characters', + }) + .max(65, { + message: 'OK but, the playbook title cannot exceed 65 characters.', + }), }); const CreatePage = () => { @@ -85,8 +90,8 @@ const CreatePage = () => { {...field} /> - - Use sentence case for your title. + + Use sentence case for your title between 45-65 characters. diff --git a/apps/lms/app/config/navbar-routes.tsx b/apps/lms/app/config/navbar-routes.tsx index b406929..52691c7 100644 --- a/apps/lms/app/config/navbar-routes.tsx +++ b/apps/lms/app/config/navbar-routes.tsx @@ -40,7 +40,7 @@ export const NavbarRoutes = ({ userId }) => { ) : null}
-
+
{ rel="noopener noreferrer" aria-label="Navigate to And Voila Discord in a new window." > - +
diff --git a/apps/lms/app/ui/learn/teacher/chapters/chapter-access-form.tsx b/apps/lms/app/ui/learn/teacher/chapters/chapter-access-form.tsx index 7c1d85d..7696ef1 100644 --- a/apps/lms/app/ui/learn/teacher/chapters/chapter-access-form.tsx +++ b/apps/lms/app/ui/learn/teacher/chapters/chapter-access-form.tsx @@ -71,7 +71,7 @@ export const ChapterAccessForm = ({
Access to the play - -
diff --git a/apps/lms/app/ui/learn/teacher/chapters/chapter-description-form.tsx b/apps/lms/app/ui/learn/teacher/chapters/chapter-description-form.tsx index ee45fc8..49437a8 100644 --- a/apps/lms/app/ui/learn/teacher/chapters/chapter-description-form.tsx +++ b/apps/lms/app/ui/learn/teacher/chapters/chapter-description-form.tsx @@ -7,6 +7,7 @@ import { Button } from '@ui/components/ui/button'; import { Form, FormControl, + FormDescription, FormField, FormItem, FormMessage, @@ -29,7 +30,15 @@ interface ChapterDescriptionFormProps { } const formSchema = z.object({ - description: z.string().min(1), + description: z.string().refine( + (value) => { + const wordCount = value.split(/\s+/).length; + return wordCount >= 150; + }, + { + message: 'Description must be at least 150 words', + }, + ), }); export const ChapterDescriptionForm = ({ @@ -77,7 +86,7 @@ export const ChapterDescriptionForm = ({
Describe the play -
- {!isEditing &&

{initialData.title}

} + {!isEditing && ( +

+ {initialData.title} +

+ )} {isEditing && (
+ + Use sentence case for the title of the play and keep it + between 45-65 characters. + )} diff --git a/apps/lms/app/ui/learn/teacher/chapters/chapter-video-form.tsx b/apps/lms/app/ui/learn/teacher/chapters/chapter-video-form.tsx index 351962b..3154809 100644 --- a/apps/lms/app/ui/learn/teacher/chapters/chapter-video-form.tsx +++ b/apps/lms/app/ui/learn/teacher/chapters/chapter-video-form.tsx @@ -59,7 +59,7 @@ export const ChapterVideoForm = ({
Video for the play - -
diff --git a/apps/lms/app/ui/learn/teacher/courses/attachment-form.tsx b/apps/lms/app/ui/learn/teacher/courses/attachment-form.tsx index 00f059c..cc018ae 100644 --- a/apps/lms/app/ui/learn/teacher/courses/attachment-form.tsx +++ b/apps/lms/app/ui/learn/teacher/courses/attachment-form.tsx @@ -74,8 +74,8 @@ export const AttachmentForm = ({ return (
- Course attachments -
{!isEditing && ( -

+

{initialData.price === 0 ? 'Free' : 'Paid'}

)} @@ -111,8 +116,8 @@ export const PriceForm = ({ initialData, courseId }: PriceFormProps) => {
{field.value - ? 'The playbook is currently Free.' - : 'The playbook is currently Paid.'} + ? 'This is a free playbook.' + : 'The is a paid playbook.'}
diff --git a/apps/lms/app/ui/learn/teacher/courses/title-form.tsx b/apps/lms/app/ui/learn/teacher/courses/title-form.tsx index 76bcfa4..a61c0cc 100644 --- a/apps/lms/app/ui/learn/teacher/courses/title-form.tsx +++ b/apps/lms/app/ui/learn/teacher/courses/title-form.tsx @@ -7,6 +7,7 @@ import { Button } from '@ui/components/ui/button'; import { Form, FormControl, + FormDescription, FormField, FormItem, FormMessage, @@ -27,9 +28,14 @@ interface TitleFormProps { } const formSchema = z.object({ - title: z.string().min(1, { - message: 'Title is required', - }), + title: z + .string() + .min(40, { + message: 'Yo! The playbook title needs at least 40 characters.', + }) + .max(65, { + message: 'Hey verbosa, keep your title under 65 characters please.', + }), }); export const TitleForm = ({ initialData, courseId }: TitleFormProps) => { @@ -68,7 +74,7 @@ export const TitleForm = ({ initialData, courseId }: TitleFormProps) => {
Playbook title -
{!isEditing && ( -

+

{initialData.title}

)} @@ -102,6 +108,9 @@ export const TitleForm = ({ initialData, courseId }: TitleFormProps) => { {...field} /> + + Use sentence case for your title between 45-65 characters. + )} diff --git a/apps/lms/app/ui/session-info.tsx b/apps/lms/app/ui/session-info.tsx index 8adccd3..91c589c 100644 --- a/apps/lms/app/ui/session-info.tsx +++ b/apps/lms/app/ui/session-info.tsx @@ -21,7 +21,7 @@ export const SessionInfo = () => { if (!session && process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production') { return ( -
+
No session found...
); @@ -30,7 +30,7 @@ export const SessionInfo = () => { return ( <> {process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production' && ( -
+

For testing purposes

User ID: {obfuscatedUserId}
diff --git a/apps/lms/app/ui/user-account-nav.tsx b/apps/lms/app/ui/user-account-nav.tsx index 0f97e7a..c1db29b 100644 --- a/apps/lms/app/ui/user-account-nav.tsx +++ b/apps/lms/app/ui/user-account-nav.tsx @@ -23,7 +23,7 @@ export function UserAccountNav({ user }: UserAccountNavProps) { diff --git a/packages/ui/components/mode-toggle.tsx b/packages/ui/components/mode-toggle.tsx index 572af87..5a44276 100644 --- a/packages/ui/components/mode-toggle.tsx +++ b/packages/ui/components/mode-toggle.tsx @@ -19,8 +19,8 @@ export function ModeToggle() {