Merge pull request #1 from teste-de-progresso/fix/feature-form-authorship-options-select
Fix/feature form authorship options select
This commit is contained in:
@@ -8,8 +8,7 @@ module Resolvers
|
|||||||
def resolve
|
def resolve
|
||||||
UserPolicy::Scope.new(@context[:current_user], User)
|
UserPolicy::Scope.new(@context[:current_user], User)
|
||||||
.resolve
|
.resolve
|
||||||
.joins(:roles)
|
.where(roles: %i[teacher nde])
|
||||||
.where(roles: { name: %i[teacher nde] })
|
|
||||||
.where.not(id: @context[:current_user].id)
|
.where.not(id: @context[:current_user].id)
|
||||||
.distinct
|
.distinct
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, {FC, useState} from 'react'
|
import React, {FC, useState} from 'react'
|
||||||
import {useForm} from 'react-hook-form';
|
import {FieldValue, FieldValues, useForm} from 'react-hook-form';
|
||||||
import {ExclamationCircleIcon} from '@heroicons/react/outline';
|
import {ExclamationCircleIcon} from '@heroicons/react/outline';
|
||||||
import {useHistory} from "react-router-dom";
|
import {useHistory} from "react-router-dom";
|
||||||
import {useDispatch, useSelector} from "react-redux";
|
import {useDispatch, useSelector} from "react-redux";
|
||||||
@@ -57,7 +57,19 @@ export const Form: FC<Props> = ({question, onSubmit, onDraftSubmit, alert}) => {
|
|||||||
const [validationErrors, setValidationErrors] = useState<string[]>([])
|
const [validationErrors, setValidationErrors] = useState<string[]>([])
|
||||||
const [confirmSaveDialogIsOpen, setConfirmFinishDialogIsOpen] = useState(false)
|
const [confirmSaveDialogIsOpen, setConfirmFinishDialogIsOpen] = useState(false)
|
||||||
const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false)
|
const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false)
|
||||||
const {register, control, setValue, getValues, reset, formState} = useForm()
|
const formHooks = useForm<FieldValues>({
|
||||||
|
defaultValues: {
|
||||||
|
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
|
||||||
|
|
||||||
const [currentStep, setCurrentStep] = useState(0)
|
const [currentStep, setCurrentStep] = useState(0)
|
||||||
const unsavedChanges = useSelector((state: RootState) => state.unsavedChanges)
|
const unsavedChanges = useSelector((state: RootState) => state.unsavedChanges)
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
@@ -119,7 +131,7 @@ export const Form: FC<Props> = ({question, onSubmit, onDraftSubmit, alert}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider props={{question, hooks: {register, control, setValue}}}>
|
<FormProvider props={{question, hooks: formHooks }}>
|
||||||
{alert && (
|
{alert && (
|
||||||
<AlertV2 severity={alert.severity} text={alert.text}></AlertV2>
|
<AlertV2 severity={alert.severity} text={alert.text}></AlertV2>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
import React, { FC, useContext } from 'react'
|
import React, { FC, useContext } from 'react';
|
||||||
import { Control, FieldValues } from 'react-hook-form';
|
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
||||||
import { Question } from '../../../__generated__/graphql-schema';
|
import { Question } from '../../../__generated__/graphql-schema';
|
||||||
|
|
||||||
type FormContextHooks = {
|
|
||||||
register: any
|
|
||||||
setValue: Function
|
|
||||||
control: Control<FieldValues>
|
|
||||||
}
|
|
||||||
|
|
||||||
type FormContextProps = {
|
type FormContextProps = {
|
||||||
hooks: FormContextHooks
|
hooks: UseFormReturn<FieldValues, object>
|
||||||
question?: Question
|
question?: Question
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
import React, { FC, useState } from "react";
|
|
||||||
import { gql } from "@apollo/client";
|
import { gql } from "@apollo/client";
|
||||||
|
import React, { FC, useState } from "react";
|
||||||
|
|
||||||
import { Card } from "../../../../../components";
|
import { Card } from "../../../../../components";
|
||||||
import { SubjectSelect, SubjectFragment } from "./SubjectSelect";
|
import { useFormProvider } from "../../FormContext";
|
||||||
import { ReviewerSelect, ReviewerFragment } from "./ReviewSelect";
|
import { ReviewerFragment, ReviewerSelect } from "./ReviewSelect";
|
||||||
import { useFormProvider } from '../../FormContext'
|
import { SubjectFragment, SubjectSelect } from "./SubjectSelect";
|
||||||
|
|
||||||
import { BLOOM_TAXONOMY, CHECK_TYPE, DIFFICULTY } from "../../../../../utils/types";
|
import {
|
||||||
import { Question } from "../../../../../__generated__/graphql-schema";
|
BLOOM_TAXONOMY,
|
||||||
|
CHECK_TYPE,
|
||||||
|
DIFFICULTY,
|
||||||
|
} from "../../../../../utils/types";
|
||||||
|
|
||||||
export const FeaturesFragment = gql`
|
export const FeaturesFragment = gql`
|
||||||
${ReviewerFragment}
|
${ReviewerFragment}
|
||||||
${SubjectFragment}
|
${SubjectFragment}
|
||||||
fragment FeaturesFields on Question {
|
fragment FeaturesFields on Question {
|
||||||
... ReviewerFields
|
...ReviewerFields
|
||||||
... SubjectFields
|
...SubjectFields
|
||||||
authorship
|
authorship
|
||||||
authorshipYear
|
authorshipYear
|
||||||
difficulty
|
difficulty
|
||||||
@@ -22,30 +25,24 @@ export const FeaturesFragment = gql`
|
|||||||
intention
|
intention
|
||||||
bloomTaxonomy
|
bloomTaxonomy
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
||||||
export const FeaturesFormStep: FC = () => {
|
export const FeaturesFormStep: FC = () => {
|
||||||
const { question, hooks: { setValue, register } } = useFormProvider();
|
const {
|
||||||
|
hooks: { setValue, register, getValues },
|
||||||
|
} = useFormProvider();
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
const {
|
const authorship = getValues("authorship");
|
||||||
authorship,
|
const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO");
|
||||||
authorshipYear,
|
|
||||||
difficulty,
|
|
||||||
bloomTaxonomy,
|
|
||||||
checkType,
|
|
||||||
} = question || {} as Question
|
|
||||||
|
|
||||||
const [ownQuestion, setOwnQuestion] = useState<boolean>(authorship === "UNIFESO" || authorship === undefined || authorship === null);
|
|
||||||
|
|
||||||
const handleOwnCheck = (value: string) => {
|
const handleOwnCheck = (value: string) => {
|
||||||
if (value === 'UNIFESO') {
|
if (value === "UNIFESO") {
|
||||||
setOwnQuestion(true)
|
setOwnQuestion(true);
|
||||||
setValue("authorship", "UNIFESO");
|
setValue("authorship", "UNIFESO");
|
||||||
setValue("authorshipYear", currentYear.toString());
|
setValue("authorshipYear", currentYear.toString());
|
||||||
} else {
|
} else {
|
||||||
setOwnQuestion(false)
|
setOwnQuestion(false);
|
||||||
setValue("authorship", "");
|
setValue("authorship", "");
|
||||||
setValue("authorshipYear", "");
|
setValue("authorshipYear", "");
|
||||||
}
|
}
|
||||||
@@ -61,25 +58,29 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
</label>
|
</label>
|
||||||
<div className="my-auto">
|
<div className="my-auto">
|
||||||
<input
|
<input
|
||||||
{...register('__nonused')}
|
{...register("authorshipType", { required: true })}
|
||||||
|
value="UNIFESO"
|
||||||
className="my-auto"
|
className="my-auto"
|
||||||
type="radio"
|
type="radio"
|
||||||
id="authorship-own"
|
id="authorship-own"
|
||||||
checked={!!ownQuestion}
|
|
||||||
onChange={() => handleOwnCheck("UNIFESO")}
|
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>
|
||||||
<div className="my-auto ml-3">
|
<div className="my-auto ml-3">
|
||||||
<input
|
<input
|
||||||
{...register('__nonused')}
|
{...register("authorshipType", { required: true })}
|
||||||
|
value="OTHER"
|
||||||
className="my-auto"
|
className="my-auto"
|
||||||
type="radio"
|
type="radio"
|
||||||
id="authorship-third"
|
id="authorship-third"
|
||||||
checked={!ownQuestion}
|
|
||||||
onChange={() => handleOwnCheck("")}
|
onChange={() => handleOwnCheck("")}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="authorship-third" className="ml-1">Outro</label>
|
<label htmlFor="authorship-third" className="ml-1">
|
||||||
|
Outro
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
@@ -88,9 +89,8 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div style={{ maxWidth: "194px" }}>
|
<div style={{ maxWidth: "194px" }}>
|
||||||
<input
|
<input
|
||||||
{...register('authorship')}
|
{...register("authorship")}
|
||||||
className="block rounded p-1 w-full border-gray-400 border shadow-sm"
|
className="block rounded p-1 w-full border-gray-400 border shadow-sm"
|
||||||
defaultValue={authorship || (ownQuestion ? "UNIFESO" : "")}
|
|
||||||
readOnly={!!ownQuestion}
|
readOnly={!!ownQuestion}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -100,13 +100,12 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
<h2 className="pr-2 pl-3 my-auto">Ano</h2>
|
<h2 className="pr-2 pl-3 my-auto">Ano</h2>
|
||||||
<div style={{ maxWidth: "62px" }}>
|
<div style={{ maxWidth: "62px" }}>
|
||||||
<input
|
<input
|
||||||
{...register('authorshipYear')}
|
{...register("authorshipYear")}
|
||||||
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
||||||
type="number"
|
type="number"
|
||||||
min="1999"
|
min="1999"
|
||||||
max={currentYear}
|
max={currentYear}
|
||||||
step="1"
|
step="1"
|
||||||
defaultValue={authorshipYear ?? new Date().getFullYear().toString()}
|
|
||||||
readOnly={!!ownQuestion}
|
readOnly={!!ownQuestion}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,9 +118,8 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<h2>Grau de Dificuldade</h2>
|
<h2>Grau de Dificuldade</h2>
|
||||||
<select
|
<select
|
||||||
{...register('difficulty')}
|
{...register("difficulty")}
|
||||||
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
||||||
defaultValue={difficulty ?? ""}
|
|
||||||
>
|
>
|
||||||
<option />
|
<option />
|
||||||
{DIFFICULTY.map((item, index) => (
|
{DIFFICULTY.map((item, index) => (
|
||||||
@@ -136,7 +134,6 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
<select
|
<select
|
||||||
{...register("checkType")}
|
{...register("checkType")}
|
||||||
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
||||||
defaultValue={checkType ?? ""}
|
|
||||||
>
|
>
|
||||||
<option />
|
<option />
|
||||||
{CHECK_TYPE.map((item, index) => (
|
{CHECK_TYPE.map((item, index) => (
|
||||||
@@ -149,9 +146,8 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<h2>Habilidade Cognitiva</h2>
|
<h2>Habilidade Cognitiva</h2>
|
||||||
<select
|
<select
|
||||||
{...register('bloomTaxonomy')}
|
{...register("bloomTaxonomy")}
|
||||||
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
className="w-full rounded p-1 border-gray-400 border shadow-sm"
|
||||||
defaultValue={bloomTaxonomy ?? ""}
|
|
||||||
>
|
>
|
||||||
<option />
|
<option />
|
||||||
{BLOOM_TAXONOMY.map((item, index) => (
|
{BLOOM_TAXONOMY.map((item, index) => (
|
||||||
@@ -171,7 +167,6 @@ export const FeaturesFormStep: FC = () => {
|
|||||||
<textarea
|
<textarea
|
||||||
{...register("intention")}
|
{...register("intention")}
|
||||||
className="block rounded p-1 w-full border-gray-400 border shadow-sm"
|
className="block rounded p-1 w-full border-gray-400 border shadow-sm"
|
||||||
defaultValue={question?.intention ?? ""}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col mt-4">
|
<div className="flex flex-col mt-4">
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export const QuestionsList: FC<Props> = ({ questions, title, pagination }) => {
|
|||||||
<div className="bg-gray-200 p-4 rounded my-2">
|
<div className="bg-gray-200 p-4 rounded my-2">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<h2 className="text-gray-500 font-medium text-xl">{title}</h2>
|
<h2 className="text-gray-500 font-medium text-xl">{title}</h2>
|
||||||
|
{questions.length > 0 &&
|
||||||
<div className="ml-auto text-sm sm:text-base text-gray-700">
|
<div className="ml-auto text-sm sm:text-base text-gray-700">
|
||||||
<button
|
<button
|
||||||
className="p-2"
|
className="p-2"
|
||||||
@@ -76,6 +77,7 @@ export const QuestionsList: FC<Props> = ({ questions, title, pagination }) => {
|
|||||||
<FaArrowRight />
|
<FaArrowRight />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<hr className="border-t border-gray-400 m-px" />
|
<hr className="border-t border-gray-400 m-px" />
|
||||||
<div className="p-2 text-sm">
|
<div className="p-2 text-sm">
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ export const formatInput = (inputs: any) =>
|
|||||||
inputs.reviewerUserId === "" ? undefined : inputs.reviewerUserId,
|
inputs.reviewerUserId === "" ? undefined : inputs.reviewerUserId,
|
||||||
alternatives: inputs.alternatives,
|
alternatives: inputs.alternatives,
|
||||||
__nonused: undefined,
|
__nonused: undefined,
|
||||||
|
authorshipType: undefined,
|
||||||
} as Question);
|
} as Question);
|
||||||
|
|||||||
Reference in New Issue
Block a user