From b3455fd0da3c9244fe90ae588c470b214f21398d Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Sun, 2 Jan 2022 22:28:04 +0300 Subject: [PATCH] feat: showing lesson video --- constants.ts | 2 +- package-lock.json | 22 +++++ package.json | 1 + .../Forms/LessonForm/CreateLessonForm.tsx | 25 ++++++ .../Forms/LessonForm/LessonForm.tsx | 82 +++++++++++++++++++ .../Forms/LessonForm/LessonForm.validator.ts | 11 +++ src/components/Forms/LessonForm/index.ts | 3 + src/components/PageElements/index.tsx | 10 ++- src/interfaces/index.ts | 4 +- .../courses/create-lesson/create-lesson.tsx | 12 ++- src/pages/courses/create/create.tsx | 21 +++-- .../edit/components/LessonList/LessonList.tsx | 2 +- src/pages/courses/edit/edit.tsx | 13 ++- src/pages/lesson/lesson.tsx | 60 +++++++++++--- src/types/index.d.ts | 11 +++ vite.config.ts | 4 + 16 files changed, 245 insertions(+), 38 deletions(-) create mode 100644 src/components/Forms/LessonForm/CreateLessonForm.tsx create mode 100644 src/components/Forms/LessonForm/LessonForm.tsx create mode 100644 src/components/Forms/LessonForm/LessonForm.validator.ts create mode 100644 src/components/Forms/LessonForm/index.ts diff --git a/constants.ts b/constants.ts index 55cc2ac..a6d4512 100644 --- a/constants.ts +++ b/constants.ts @@ -1 +1 @@ -export const BACKEND_URL: string = 'http://localhost:3333'; +export const BACKEND_URL = 'http://localhost:3333'; diff --git a/package-lock.json b/package-lock.json index ff14158..2bcda27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1741,6 +1741,11 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "deepmerge": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", + "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -2849,6 +2854,11 @@ "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=" }, + "load-script": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/load-script/-/load-script-1.0.0.tgz", + "integrity": "sha1-BJGTngvuVkPuSUp+PaPSuscMbKQ=" + }, "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -3324,6 +3334,18 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, + "react-player": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/react-player/-/react-player-2.9.0.tgz", + "integrity": "sha512-jNUkTfMmUhwPPAktAdIqiBcVUKsFKrVGH6Ocutj6535CNfM91yrvWxHg6fvIX8Y/fjYUPoejddwh7qboNV9vGA==", + "requires": { + "deepmerge": "^4.0.0", + "load-script": "^1.0.0", + "memoize-one": "^5.1.1", + "prop-types": "^15.7.2", + "react-fast-compare": "^3.0.1" + } + }, "react-redux": { "version": "7.2.6", "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.2.6.tgz", diff --git a/package.json b/package.json index f735c49..fad5354 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "react-helmet": "^6.1.0", "react-hook-form": "^7.12.2", "react-icons": "^4.3.1", + "react-player": "^2.9.0", "react-router-dom": "^5.2.0", "react-spinners": "^0.11.0", "react-virtuoso": "^2.2.8", diff --git a/src/components/Forms/LessonForm/CreateLessonForm.tsx b/src/components/Forms/LessonForm/CreateLessonForm.tsx new file mode 100644 index 0000000..3165be4 --- /dev/null +++ b/src/components/Forms/LessonForm/CreateLessonForm.tsx @@ -0,0 +1,25 @@ +import { yupResolver } from '@hookform/resolvers/yup'; +import React from 'react'; +import { SubmitHandler, useForm } from 'react-hook-form'; +import { LessonForm } from '.'; +import { InputFields } from './LessonForm'; +import LessonFormSchema from './LessonForm.validator'; + +const CreateLessonForm: React.FC = () => { + const form = useForm({ resolver: yupResolver(LessonFormSchema) }); + + const onSubmit: SubmitHandler = async data => { + console.log('creating...'); + }; + + return ( + + ); +}; + +export default CreateLessonForm; diff --git a/src/components/Forms/LessonForm/LessonForm.tsx b/src/components/Forms/LessonForm/LessonForm.tsx new file mode 100644 index 0000000..3f14cb1 --- /dev/null +++ b/src/components/Forms/LessonForm/LessonForm.tsx @@ -0,0 +1,82 @@ +import React from 'react'; +import { + FormControl, + FormHelperText, + FormLabel, + Text, + Input, + InputGroup, + Stack, + Box, + Button, + Textarea, + Flex, +} from '@chakra-ui/react'; +import { UseFormReturn } from 'react-hook-form'; + +export type InputFields = { + title: string; + description: string; +}; + +export type LessonFormPropsType = { + onSubmit: () => Promise; + buttonLabel: string; + isLoading: boolean; + reactHookForm: UseFormReturn; +}; + +const LessonForm: React.FC = ({ onSubmit, buttonLabel, isLoading, reactHookForm }) => { + const { + control, + register, + watch, + formState: { errors, isDirty }, + } = reactHookForm; + + return ( +
+ + + Title + + + + e.g Variables in Javascript + + {errors.title?.message} + + + + + Description +