fix reviews query

This commit is contained in:
João Geonizeli
2022-08-10 18:26:17 +00:00
parent f9fc5fc3a7
commit 483234de31
4 changed files with 42 additions and 39 deletions

View File

@@ -59,8 +59,13 @@ export const Form: FC<Props> = ({question, onSubmit, onDraftSubmit, alert}) => {
const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false)
const formHooks = useForm<FieldValues>({
defaultValues: {
authorship: 'UNIFESO',
authorship: question?.authorship ?? 'UNIFESO',
authorshipType: question?.authorship === 'UNIFESO' ? 'UNIFESO' : 'OTHER',
authorshipYear: new Date().getFullYear().toString(),
difficulty: question?.difficulty,
checkType: question?.checkType,
bloomTaxonomy: question?.bloomTaxonomy,
intention: question?.intention,
}
})
const {register, control, setValue, getValues, reset, formState, resetField} = formHooks

View File

@@ -1,20 +1,23 @@
import React, { FC, useState } from "react";
import { gql } from "@apollo/client";
import React, { FC, useState } from "react";
import { Card } from "../../../../../components";
import { SubjectSelect, SubjectFragment } from "./SubjectSelect";
import { ReviewerSelect, ReviewerFragment } from "./ReviewSelect";
import { useFormProvider } from '../../FormContext'
import { useFormProvider } from "../../FormContext";
import { ReviewerFragment, ReviewerSelect } from "./ReviewSelect";
import { SubjectFragment, SubjectSelect } from "./SubjectSelect";
import { BLOOM_TAXONOMY, CHECK_TYPE, DIFFICULTY } from "../../../../../utils/types";
import { Question } from "../../../../../__generated__/graphql-schema";
import {
BLOOM_TAXONOMY,
CHECK_TYPE,
DIFFICULTY,
} from "../../../../../utils/types";
export const FeaturesFragment = gql`
${ReviewerFragment}
${SubjectFragment}
fragment FeaturesFields on Question {
... ReviewerFields
... SubjectFields
...ReviewerFields
...SubjectFields
authorship
authorshipYear
difficulty
@@ -22,31 +25,24 @@ export const FeaturesFragment = gql`
intention
bloomTaxonomy
}
`
`;
export const FeaturesFormStep: FC = () => {
const { question, hooks: { setValue, register, formState, getValues } } = useFormProvider();
const {
hooks: { setValue, register, getValues },
} = useFormProvider();
const currentYear = new Date().getFullYear();
if (!question) return null
const {
difficulty,
bloomTaxonomy,
checkType,
} = question
const authorship = getValues('authorship')
const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO")
const authorship = getValues("authorship");
const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO");
const handleOwnCheck = (value: string) => {
if (value === 'UNIFESO') {
setOwnQuestion(true)
if (value === "UNIFESO") {
setOwnQuestion(true);
setValue("authorship", "UNIFESO");
setValue("authorshipYear", currentYear.toString());
} else {
setOwnQuestion(false)
setOwnQuestion(false);
setValue("authorship", "");
setValue("authorshipYear", "");
}
@@ -62,23 +58,29 @@ export const FeaturesFormStep: FC = () => {
</label>
<div className="my-auto">
<input
{...register("authorshipType", { required: true })}
value="UNIFESO"
className="my-auto"
type="radio"
id="authorship-own"
checked={!!ownQuestion}
onChange={() => handleOwnCheck("UNIFESO")}
/>
<label htmlFor="authorship-own" className="ml-1">Própria</label>
<label htmlFor="authorship-own" className="ml-1">
Própria
</label>
</div>
<div className="my-auto ml-3">
<input
{...register("authorshipType", { required: true })}
value="OTHER"
className="my-auto"
type="radio"
id="authorship-third"
checked={!ownQuestion}
onChange={() => handleOwnCheck("")}
/>
<label htmlFor="authorship-third" className="ml-1">Outro</label>
<label htmlFor="authorship-third" className="ml-1">
Outro
</label>
</div>
</div>
<div className="flex">
@@ -87,7 +89,7 @@ export const FeaturesFormStep: FC = () => {
<div className="w-full">
<div style={{ maxWidth: "194px" }}>
<input
{...register('authorship')}
{...register("authorship")}
className="block rounded p-1 w-full border-gray-400 border shadow-sm"
readOnly={!!ownQuestion}
/>
@@ -98,7 +100,7 @@ export const FeaturesFormStep: FC = () => {
<h2 className="pr-2 pl-3 my-auto">Ano</h2>
<div style={{ maxWidth: "62px" }}>
<input
{...register('authorshipYear')}
{...register("authorshipYear")}
className="w-full rounded p-1 border-gray-400 border shadow-sm"
type="number"
min="1999"
@@ -116,9 +118,8 @@ export const FeaturesFormStep: FC = () => {
<div className="flex flex-col">
<h2>Grau de Dificuldade</h2>
<select
{...register('difficulty')}
{...register("difficulty")}
className="w-full rounded p-1 border-gray-400 border shadow-sm"
defaultValue={difficulty ?? ""}
>
<option />
{DIFFICULTY.map((item, index) => (
@@ -133,7 +134,6 @@ export const FeaturesFormStep: FC = () => {
<select
{...register("checkType")}
className="w-full rounded p-1 border-gray-400 border shadow-sm"
defaultValue={checkType ?? ""}
>
<option />
{CHECK_TYPE.map((item, index) => (
@@ -146,9 +146,8 @@ export const FeaturesFormStep: FC = () => {
<div className="w-full">
<h2>Habilidade Cognitiva</h2>
<select
{...register('bloomTaxonomy')}
{...register("bloomTaxonomy")}
className="w-full rounded p-1 border-gray-400 border shadow-sm"
defaultValue={bloomTaxonomy ?? ""}
>
<option />
{BLOOM_TAXONOMY.map((item, index) => (
@@ -168,7 +167,6 @@ export const FeaturesFormStep: FC = () => {
<textarea
{...register("intention")}
className="block rounded p-1 w-full border-gray-400 border shadow-sm"
defaultValue={question?.intention ?? ""}
/>
</div>
<div className="flex flex-col mt-4">

View File

@@ -12,4 +12,5 @@ export const formatInput = (inputs: any) =>
inputs.reviewerUserId === "" ? undefined : inputs.reviewerUserId,
alternatives: inputs.alternatives,
__nonused: undefined,
authorshipType: undefined,
} as Question);