Commit 5fb4d6da authored by Vladimir Kurganov's avatar Vladimir Kurganov
Browse files

add note to questionnaire

parent e4326cf9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -119,4 +119,9 @@ export const QUESTIONNAIRE_QUESTION_FORM: Form = {
    tooltip: '',
    optional: true,
  },
  note: {
    label: 'Note',
    tooltip: '',
    optional: true,
  },
}
+20 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ type State<
    text: string
    valid: boolean
    multiline: boolean
    note?: string
    update: (id?: number) => Promise<void>
  },
> = S & ZustandSetterSingle<S>
@@ -59,12 +60,13 @@ const FreeformForm: FC<QuestionnaireQuestionFormProps> = ({
    computed((set, get) => ({
      text: '',
      multiline: false,
      note: '',
      ...compute(get, state => ({
        valid: state.text !== '',
      })),
      set: (item, value) => set({ [item]: value }),
      update: async id => {
        const { multiline, text } = get()
        const { multiline, text, note } = get()

        const relatedMilestones = (
          await db.questionnaireMilestones
@@ -78,6 +80,7 @@ const FreeformForm: FC<QuestionnaireQuestionFormProps> = ({
            injectInfoId,
            type: 'free-form',
            text,
            note,
          },
          {
            multiline,
@@ -98,6 +101,7 @@ const FreeformForm: FC<QuestionnaireQuestionFormProps> = ({
    state.setState({
      text: questionnaireQuestion?.text,
      multiline: freeformQuestion?.multiline,
      note: questionnaireQuestion?.note,
    })
  }, [isOpen, state, questionnaireQuestion, freeformQuestion])

@@ -166,6 +170,21 @@ const FreeformForm: FC<QuestionnaireQuestionFormProps> = ({
            questionId={freeformQuestion?.id}
            injectInfoId={injectInfoId}
          />
          <TooltipLabel label={QUESTIONNAIRE_QUESTION_FORM.note}>
            <ShallowGetSet
              store={state}
              get={({ note }) => note}
              set={({ set }) => set}
            >
              {(note, set) => (
                <InputGroup
                  placeholder='Input note'
                  value={note}
                  onChange={e => set('note', e.target.value)}
                />
              )}
            </ShallowGetSet>
          </TooltipLabel>
        </DialogBody>
        <DialogFooter
          actions={
+7 −1
Original line number Diff line number Diff line
import { Button, ButtonGroup, Card } from '@blueprintjs/core'
import { Button, ButtonGroup, Card, Classes } from '@blueprintjs/core'
import { notify } from '@inject/shared'
import { useLiveQuery } from 'dexie-react-hooks'
import { range } from 'lodash'
@@ -95,6 +95,9 @@ const QuestionnaireQuestionRadio: FC<QuestionnaireQuestionProps> = ({
          </li>
        ))}
      </ol>
      <span className={Classes.TEXT_MUTED} style={{ flexGrow: 1 }}>
        {questionnaireQuestion.note}
      </span>
    </Card>
  )
}
@@ -159,6 +162,9 @@ const QuestionnaireQuestionFreeform: FC<QuestionnaireQuestionProps> = ({
          />
        </ButtonGroup>
      </div>
      <span className={Classes.TEXT_MUTED} style={{ flexGrow: 1 }}>
        {questionnaireQuestion.note}
      </span>
    </Card>
  )
}
+22 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ type State<
    customLabels: boolean
    labels: string
    valid: boolean
    note?: string
  },
> = S & ZustandSetterSingle<S>

@@ -61,6 +62,7 @@ const RadioForm: FC<QuestionnaireQuestionFormProps> = ({
      correct: 0,
      customLabels: false,
      labels: '',
      note: '',
      ...compute(get, state => ({
        valid:
          state.text !== '' &&
@@ -78,6 +80,7 @@ const RadioForm: FC<QuestionnaireQuestionFormProps> = ({
      correct: radioQuestion?.correct,
      customLabels: !!radioQuestion?.labels,
      labels: radioQuestion?.labels,
      note: questionnaireQuestion?.note,
    })
  }, [
    isOpen,
@@ -86,17 +89,20 @@ const RadioForm: FC<QuestionnaireQuestionFormProps> = ({
    radioQuestion?.correct,
    radioQuestion?.labels,
    questionnaireQuestion?.text,
    questionnaireQuestion?.note,
  ])

  const handleUpdateButton = useCallback(async () => {
    try {
      const { correct, customLabels, text, labels, max } = state.getState()
      const { correct, customLabels, text, labels, max, note } =
        state.getState()
      await updateQuestionnaireQuestion(
        {
          id: questionnaireQuestion?.id,
          injectInfoId,
          type: 'radio',
          text,
          note,
        },
        {
          max: customLabels ? labels.split(', ').length : max,
@@ -213,6 +219,21 @@ const RadioForm: FC<QuestionnaireQuestionFormProps> = ({
            }
          </ShallowGet>

          <TooltipLabel label={QUESTIONNAIRE_QUESTION_FORM.note}>
            <ShallowGetSet
              store={state}
              get={({ note }) => note}
              set={({ set }) => set}
            >
              {(note, set) => (
                <InputGroup
                  placeholder='Input note'
                  value={note}
                  onChange={e => set('note', e.target.value)}
                />
              )}
            </ShallowGetSet>
          </TooltipLabel>
          {}
        </DialogBody>
        <DialogFooter
+1 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ export type QuestionnaireQuestion = {
  text: string
  injectInfoId: number
  type: 'free-form' | 'radio'
  note?: string
}

export type QuestionnaireQuestionFreeForm = {
Loading