diff --git a/app/javascript/application.tsx b/app/javascript/application.tsx index 481b426..9446a6c 100644 --- a/app/javascript/application.tsx +++ b/app/javascript/application.tsx @@ -4,23 +4,24 @@ import { Provider } from "react-redux"; import { BrowserRouter } from "react-router-dom"; import { Appbar } from "./components"; -import { ApolloContext } from "./contexts"; +import { ApolloContext, UserContext } from "./contexts"; import { PrivateRoutes } from "./routes"; import { store } from "./services/store"; export const App = () => { return ( - - - - - - - - + + + + + + + + + + ); -} - +}; const container = document.getElementById("app"); diff --git a/app/javascript/components/List/List.tsx b/app/javascript/components/List/List.tsx index d75c0b8..f0f6981 100644 --- a/app/javascript/components/List/List.tsx +++ b/app/javascript/components/List/List.tsx @@ -43,6 +43,7 @@ export const ListItem: FC = ({ icon, text, children }) => { type ListProps = { className?: string + children: React.ReactNode } export const List: FC = ({ diff --git a/app/javascript/components/Modal/Modal.tsx b/app/javascript/components/Modal/Modal.tsx index 9e2c093..90fcbbe 100644 --- a/app/javascript/components/Modal/Modal.tsx +++ b/app/javascript/components/Modal/Modal.tsx @@ -7,6 +7,7 @@ type Props = { buttons?: any, title: string, className?: string, + children: React.ReactNode } export const Modal: FC = ({ diff --git a/app/javascript/contexts/UserContext.tsx b/app/javascript/contexts/UserContext.tsx index ed2c11a..39e6774 100644 --- a/app/javascript/contexts/UserContext.tsx +++ b/app/javascript/contexts/UserContext.tsx @@ -11,14 +11,12 @@ export type UserContext = { user?: Query['currentUser'] refetch: () => void isOnlyTeacher: boolean - authToken: string } const Context = createContext({ refetch: () => { }, isOnlyTeacher: false, - authToken: '' }) export const useCurrentUser = (): UserContext => { @@ -44,10 +42,9 @@ const CurrentUserQuery = gql` type Props = { children: any - authToken: string } -export const UserContext: FC = ({ children, authToken }) => { +export const UserContext: FC = ({ children }) => { const [user, setUser] = useState(); const isOnlyTeacher = !!(user?.roles.includes(UserRole.Teacher) && user?.roles.length === 1) @@ -67,7 +64,7 @@ export const UserContext: FC = ({ children, authToken }) => { if (!user) return return ( - + {children} ); diff --git a/app/javascript/pages/dashboard/Filters.tsx b/app/javascript/pages/dashboard/Filters.tsx index 42c83bd..3ba3ea2 100644 --- a/app/javascript/pages/dashboard/Filters.tsx +++ b/app/javascript/pages/dashboard/Filters.tsx @@ -44,9 +44,7 @@ const FiltersForm: FC = () => { const {user, isOnlyTeacher} = userContext const onSubmit = (values: FilterBarForm) => { - reset(getValues(), { - isDirty: false - }) + reset(getValues()) setWhere(mapFilter(values, user?.id)) } @@ -66,7 +64,7 @@ const FiltersForm: FC = () => { { @@ -96,8 +93,7 @@ const FiltersForm: FC = () => { id={"fromOtherUsers"} type="checkbox" placeholder="fromOtherUsers" - ref={register} - name={"fromOtherUsers"} + {...register('fromOtherUsers')} /> )} diff --git a/app/javascript/pages/question/Form/Form.tsx b/app/javascript/pages/question/Form/Form.tsx index 35e5824..304815a 100644 --- a/app/javascript/pages/question/Form/Form.tsx +++ b/app/javascript/pages/question/Form/Form.tsx @@ -97,9 +97,7 @@ export const Form: FC = ({question, onSubmit, onDraftSubmit, alert}) => { const handleDraftSave = () => { if (onDraftSubmit) { onDraftSubmit({...getFormattedInputValues(), status: QuestionStatus.Draft} as QuestionCreateInput) - reset(getValues(), { - isDirty: false - }) + reset(getValues()) dispatch(turnOff()) } } @@ -117,9 +115,7 @@ export const Form: FC = ({question, onSubmit, onDraftSubmit, alert}) => { setValidationErrors(errors) } - reset(getValues(), { - isDirty: false - }) + reset(getValues()) } return ( diff --git a/app/javascript/pages/question/Form/components/TextEditor.tsx b/app/javascript/pages/question/Form/components/TextEditor.tsx index 9acba4f..d9a1521 100644 --- a/app/javascript/pages/question/Form/components/TextEditor.tsx +++ b/app/javascript/pages/question/Form/components/TextEditor.tsx @@ -1,7 +1,7 @@ import React, { FC } from "react"; import { Controller } from "react-hook-form"; import CKEditor from "@ckeditor/ckeditor5-react"; -import * as ClassicEditor from "ckeditor5-mathtype/build/ckeditor"; +import ClassicEditor from "ckeditor5-mathtype/build/ckeditor"; import { useFormProvider } from '../FormContext' @@ -37,7 +37,9 @@ export const TextEditor: FC = ({ name, defaultValue }) => { control={control} name={name} defaultValue={defaultValue} - render={({ onChange, value }) => ( + render={({ + field: { onChange, value } + }) => ( { handleOwnCheck("UNIFESO")} - name="__nonused" /> Própria handleOwnCheck("")} - name="__nonused" /> Outro @@ -90,9 +88,8 @@ export const FeaturesFormStep: FC = () => { @@ -103,13 +100,12 @@ export const FeaturesFormStep: FC = () => { Ano @@ -123,9 +119,8 @@ export const FeaturesFormStep: FC = () => { Grau de Dificuldade @@ -139,9 +134,8 @@ export const FeaturesFormStep: FC = () => { Tipo @@ -155,9 +149,8 @@ export const FeaturesFormStep: FC = () => { Habilidade Cognitiva @@ -176,9 +169,8 @@ export const FeaturesFormStep: FC = () => { Intenção diff --git a/app/javascript/pages/question/Form/steps/FeaturesFromStep/ReviewSelect.tsx b/app/javascript/pages/question/Form/steps/FeaturesFromStep/ReviewSelect.tsx index c140c22..400a5c4 100644 --- a/app/javascript/pages/question/Form/steps/FeaturesFromStep/ReviewSelect.tsx +++ b/app/javascript/pages/question/Form/steps/FeaturesFromStep/ReviewSelect.tsx @@ -38,9 +38,8 @@ export const ReviewerSelect: FC = () => { return ( {(question?.status === undefined || question?.status === QuestionStatus.Draft) && } diff --git a/app/javascript/pages/question/Form/steps/FeaturesFromStep/SubjectSelect.tsx b/app/javascript/pages/question/Form/steps/FeaturesFromStep/SubjectSelect.tsx index e882d18..04ae357 100644 --- a/app/javascript/pages/question/Form/steps/FeaturesFromStep/SubjectSelect.tsx +++ b/app/javascript/pages/question/Form/steps/FeaturesFromStep/SubjectSelect.tsx @@ -50,9 +50,8 @@ export const SubjectSelect: FC = () => { Assunto setSelectedId(e.target.value)} > diff --git a/app/javascript/pages/question/List/QuestionFilter/AuthorshipFilter.tsx b/app/javascript/pages/question/List/QuestionFilter/AuthorshipFilter.tsx index b236cf1..ad8517f 100644 --- a/app/javascript/pages/question/List/QuestionFilter/AuthorshipFilter.tsx +++ b/app/javascript/pages/question/List/QuestionFilter/AuthorshipFilter.tsx @@ -31,9 +31,8 @@ export const AuthorshipFilter: FC = ({ setChanged, register }) => { {options.map(({ value, label }, index) => ( = ({ register, setChanged return ( setChanged(true)} > diff --git a/app/javascript/pages/question/List/QuestionFilter/QuestionsFilter.tsx b/app/javascript/pages/question/List/QuestionFilter/QuestionsFilter.tsx index 6bcaea9..9a01aee 100644 --- a/app/javascript/pages/question/List/QuestionFilter/QuestionsFilter.tsx +++ b/app/javascript/pages/question/List/QuestionFilter/QuestionsFilter.tsx @@ -44,7 +44,7 @@ const FilterGroup: FC = ({ setChanged(true)} diff --git a/app/javascript/pages/question/List/QuestionFilter/QuestionsSubjectFilter.tsx b/app/javascript/pages/question/List/QuestionFilter/QuestionsSubjectFilter.tsx index df5654a..f2be614 100644 --- a/app/javascript/pages/question/List/QuestionFilter/QuestionsSubjectFilter.tsx +++ b/app/javascript/pages/question/List/QuestionFilter/QuestionsSubjectFilter.tsx @@ -31,9 +31,8 @@ export const QuestionsSubjectFilter: FC = ({ register, setChanged }) => { return ( setChanged(true)} > diff --git a/app/javascript/pages/question/shared/ReviewMessages/ReviewMessagesForm.tsx b/app/javascript/pages/question/shared/ReviewMessages/ReviewMessagesForm.tsx index fc0ec2f..4d97394 100644 --- a/app/javascript/pages/question/shared/ReviewMessages/ReviewMessagesForm.tsx +++ b/app/javascript/pages/question/shared/ReviewMessages/ReviewMessagesForm.tsx @@ -1,6 +1,6 @@ import { ApolloQueryResult, gql, OperationVariables, useMutation } from "@apollo/client"; import React, { FC, useState } from "react"; -import { useForm } from "react-hook-form"; +import { FieldValues, SubmitHandler, useForm } from "react-hook-form"; import { Prompt, useHistory } from "react-router"; import { Button, Card } from "../../../../components"; import { useCurrentUser } from "../../../../contexts"; @@ -52,8 +52,9 @@ export const ReviewMessageForm: FC<{ question: Question refetch: (variables?: Partial | undefined) => Promise> }> = ({ question, refetch }) => { - const [isChangesSaved, setIsChangesSaved] = useState(true) - const { register, handleSubmit } = useForm() + const { register, handleSubmit, formState: { + isDirty + } } = useForm() const history = useHistory(); const { user } = useCurrentUser() @@ -62,26 +63,14 @@ export const ReviewMessageForm: FC<{ const hasFeebacks = !!question.reviewMessages.nodes.length const questionIsFromCurrentUser = user?.id === question.user.id - const handleTextChange = (e: React.ChangeEvent) => { - if (e.target.value !== '') { - setIsChangesSaved(false) - } else { - setIsChangesSaved(true) - } - } - - const handleSubmitClick = () => { - setIsChangesSaved(true) - } - - const formSubmit = async (inputs: { - feedbackType: ReviewMessageFeedbackType - text: string + const formSubmit: SubmitHandler = async ({ + feedbackType, + text }) => { await createReviewMessage({ variables: { - text: inputs.text, - feedbackType: questionIsFromCurrentUser ? ReviewMessageFeedbackType.Answer : inputs.feedbackType, + text: text, + feedbackType: questionIsFromCurrentUser ? ReviewMessageFeedbackType.Answer : feedbackType, questionId: NodeId.decode(question.id).id, }, }); @@ -96,15 +85,14 @@ export const ReviewMessageForm: FC<{ return ( <> handleTextChange(e)} className="w-full h-32 p-2 border-solid border-2 border-gray-700 rounded-md" - ref={register} + {...register('text')} name="text" /> {!questionIsFromCurrentUser && REVIEW_FEEDBACK.map((item, index) => ( @@ -112,8 +100,7 @@ export const ReviewMessageForm: FC<{ ))} - + {questionIsFromCurrentUser ? 'Responder Parecer' : 'Enviar Parecer'} diff --git a/package.json b/package.json index a36b49f..4242664 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "private": "true", "dependencies": { "@apollo/client": "^3.6.9", - "@ckeditor/ckeditor5-react": "^5.0.2", + "@ckeditor/ckeditor5-build-classic": "^21.0.0", + "@ckeditor/ckeditor5-react": "^2.1.0", "@headlessui/react": "^1.6.6", "@heroicons/react": "^1.0.6", "@nivo/core": "^0.79.0", @@ -17,7 +18,7 @@ "react": "^18.2.0", "react-avatar-edit": "^1.2.0", "react-dom": "^18.2.0", - "react-hook-form": "^6.2.0", + "react-hook-form": "^7.33.1", "react-icons": "^4.4.0", "react-redux": "^8.0.2", "react-router-dom": "^5.2.0", diff --git a/yarn.lock b/yarn.lock index 352759f..55b4a87 100644 --- a/yarn.lock +++ b/yarn.lock @@ -136,12 +136,17 @@ "@babel/helper-validator-identifier" "^7.18.6" to-fast-properties "^2.0.0" -"@ckeditor/ckeditor5-react@^5.0.2": - version "5.0.2" - resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-react/-/ckeditor5-react-5.0.2.tgz#446518e1d7ce842c63fc6ac24e818cc78a753903" - integrity sha512-pN4acvCAIsuXaZDMttqy4dNBKXiJ6AS6P8NM3ggMc/rQkMIPp3YPhDWWf+pyQLUiewj1Bfr5EFeBfcXPQTOn+Q== +"@ckeditor/ckeditor5-build-classic@^21.0.0": + version "21.0.0" + resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-build-classic/-/ckeditor5-build-classic-21.0.0.tgz#f34624fa28edbc4de917eee326db7de1f09c9c63" + integrity sha512-IYPXmc5Np7SzJVJbGNZk3OZEHnZ/WylbN1aFyfYdKMch9Be8mrCB9QQOqfsAEKD4SjXujYvn1jL0mM/EPZ8ECw== + +"@ckeditor/ckeditor5-react@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-react/-/ckeditor5-react-2.1.0.tgz#f612546a5a328899a436d71b72ffd632600049e8" + integrity sha512-rlHjRKhwP9tNK0Yj2UJShL14mRfxLPgJ+Pv6zTv/Mvmd4wrwGnJf+5ybOAGK92S02hP1cXH+9km+PRO1b4V+ng== dependencies: - prop-types "^15.7.2" + prop-types "^15.6.1" "@emotion/is-prop-valid@^1.1.0": version "1.1.3" @@ -1700,7 +1705,7 @@ pretty-hrtime@^1.0.3: resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1" integrity sha512-66hKPCr+72mlfiSjlEB1+45IjXSqvVAIy6mocupoww4tBFE9R9IhwwUGoI4G++Tc9Aq+2rxOt0RFU6gPcrte0A== -prop-types@^15.6.2, prop-types@^15.7.2: +prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== @@ -1741,10 +1746,10 @@ react-dom@^18.2.0: loose-envify "^1.1.0" scheduler "^0.23.0" -react-hook-form@^6.2.0: - version "6.15.8" - resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-6.15.8.tgz#725c139d308c431c4611e4b9d85a49f01cfc0e7a" - integrity sha512-prq82ofMbnRyj5wqDe8hsTRcdR25jQ+B8KtCS7BLCzjFHAwNuCjRwzPuP4eYLsEBjEIeYd6try+pdLdw0kPkpg== +react-hook-form@^7.33.1: + version "7.33.1" + resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.33.1.tgz#8c4410e3420788d3b804d62cc4c142915c2e46d0" + integrity sha512-ydTfTxEJdvgjCZBj5DDXRc58oTEfnFupEwwTAQ9FSKzykEJkX+3CiAkGtAMiZG7IPWHuzgT6AOBfogiKhUvKgg== react-icons@^4.4.0: version "4.4.0"