Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mandatory checkbox in integer question type #44

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/views/Login/ForgotPassword/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ export function Component() {
setError,
(val) => {
elementRef.current?.resetCaptcha();
// eslint-disable-next-line no-console
console.log('submit value', val);
forgotPasswordTrigger({
variables: {
input: val as PasswordResetTriggerInput,
Expand Down
11 changes: 11 additions & 0 deletions src/views/QuestionnaireEdit/DateQuestionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@togglecorp/fujs';
import {
Button,
Checkbox,
TextInput,
useAlert,
} from '@the-deep/deep-ui';
Expand Down Expand Up @@ -115,6 +116,9 @@ const schema: FormSchema = {
requiredValidation: requiredStringCondition,
},
hint: {},
required: {
defaultValue: false,
},
}),
};

Expand Down Expand Up @@ -182,6 +186,7 @@ function DateQuestionForm(props: Props) {
label: questionResponse?.label,
leafGroup: questionResponse?.leafGroupId,
hint: questionResponse?.hint,
required: questionResponse?.required,
});
},
},
Expand Down Expand Up @@ -326,6 +331,12 @@ function DateQuestionForm(props: Props) {
disabled
/>
</div>
<Checkbox
name="required"
label="Make question mandatory"
onChange={setFieldValue}
value={formValue.required}
/>
<Button
name={undefined}
className={styles.button}
Expand Down
9 changes: 9 additions & 0 deletions src/views/QuestionnaireEdit/FileQuestionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TextInput,
Button,
useAlert,
Checkbox,
} from '@the-deep/deep-ui';
import {
gql,
Expand Down Expand Up @@ -41,6 +42,7 @@ import {
QUESTION_FRAGMENT,
QUESTION_INFO,
} from '../queries.ts';

import styles from './index.module.css';

const CREATE_FILE_QUESTION = gql`
Expand Down Expand Up @@ -182,6 +184,7 @@ function FileQuestionForm(props: Props) {
label: questionResponse?.label,
leafGroup: questionResponse?.leafGroupId,
hint: questionResponse?.hint,
required: questionResponse?.required,
});
},
},
Expand Down Expand Up @@ -325,6 +328,12 @@ function FileQuestionForm(props: Props) {
disabled
/>
</div>
<Checkbox
name="required"
label="Make question mandatory"
onChange={setFieldValue}
value={formValue.required}
/>
<Button
name={undefined}
className={styles.button}
Expand Down
11 changes: 11 additions & 0 deletions src/views/QuestionnaireEdit/ImageQuestionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TextInput,
Button,
useAlert,
Checkbox,
} from '@the-deep/deep-ui';
import {
gql,
Expand Down Expand Up @@ -115,6 +116,9 @@ const schema: FormSchema = {
requiredValidation: requiredStringCondition,
},
hint: {},
required: {
defaultValue: false,
},
}),
};

Expand Down Expand Up @@ -182,6 +186,7 @@ function ImageQuestionForm(props: Props) {
label: questionResponse?.label,
leafGroup: questionResponse?.leafGroupId,
hint: questionResponse?.hint,
required: questionResponse?.required,
});
},
},
Expand Down Expand Up @@ -324,6 +329,12 @@ function ImageQuestionForm(props: Props) {
disabled
/>
</div>
<Checkbox
name="required"
label="Make question mandatory"
onChange={setFieldValue}
value={formValue.required}
/>
<Button
name={undefined}
className={styles.button}
Expand Down
13 changes: 12 additions & 1 deletion src/views/QuestionnaireEdit/IntegerQuestionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@togglecorp/fujs';
import {
Button,
Checkbox,
TextInput,
useAlert,
} from '@the-deep/deep-ui';
Expand Down Expand Up @@ -89,7 +90,7 @@ type FormSchema = ObjectSchema<FormType>;
type FormSchemaFields = ReturnType<FormSchema['fields']>;

const schema: FormSchema = {
fields: () : FormSchemaFields => ({
fields: (): FormSchemaFields => ({
name: {
required: true,
requiredValidation: requiredStringCondition,
Expand All @@ -111,6 +112,9 @@ const schema: FormSchema = {
requiredValidation: requiredStringCondition,
},
hint: {},
required: {
defaultValue: false,
},
}),
};

Expand Down Expand Up @@ -178,6 +182,7 @@ function IntegerQuestionForm(props: Props) {
label: questionResponse?.label,
leafGroup: questionResponse?.leafGroupId,
hint: questionResponse?.hint,
required: questionResponse?.required,
});
},
},
Expand Down Expand Up @@ -322,6 +327,12 @@ function IntegerQuestionForm(props: Props) {
disabled
/>
</div>
<Checkbox
name="required"
label="Make question mandatory"
onChange={setFieldValue}
value={formValue.required}
/>
<Button
name={undefined}
className={styles.button}
Expand Down
11 changes: 11 additions & 0 deletions src/views/QuestionnaireEdit/NoteQuestionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TextInput,
Button,
useAlert,
Checkbox,
} from '@the-deep/deep-ui';
import {
gql,
Expand Down Expand Up @@ -115,6 +116,9 @@ const schema: FormSchema = {
required: true,
requiredValidation: requiredStringCondition,
},
required: {
defaultValue: false,
},
}),
};

Expand Down Expand Up @@ -182,6 +186,7 @@ function NoteQuestionForm(props: Props) {
label: questionResponse?.label,
leafGroup: questionResponse?.leafGroupId,
hint: questionResponse?.hint,
required: questionResponse?.required,
});
},
},
Expand Down Expand Up @@ -317,6 +322,12 @@ function NoteQuestionForm(props: Props) {
disabled
/>
</div>
<Checkbox
name="required"
label="Make question mandatory"
onChange={setFieldValue}
value={formValue.required}
/>
<Button
name={undefined}
className={styles.button}
Expand Down
2 changes: 1 addition & 1 deletion src/views/QuestionnaireEdit/QuestionList/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
padding: var(--dui-spacing-medium);

.heading {
color: var(--dui-color-dark);
color: var(--text-color-dark);
font-weight: var(--dui-font-weight-bold);
}
.header-actions {
Expand Down
10 changes: 10 additions & 0 deletions src/views/QuestionnaireEdit/QuestionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface QuestionRendererProps {
handleQuestionAdd: (groupId: string) => void;
addQuestionPaneShown: boolean;
selectedGroups: string[];
setSelectedLeafGroupId: React.Dispatch<React.SetStateAction<string | undefined>>;
}

function QuestionListRenderer(props: QuestionRendererProps) {
Expand All @@ -97,6 +98,7 @@ function QuestionListRenderer(props: QuestionRendererProps) {
level,
handleQuestionAdd,
addQuestionPaneShown,
setSelectedLeafGroupId,
} = props;

const questionsVariables = useMemo(() => {
Expand Down Expand Up @@ -158,13 +160,15 @@ function QuestionListRenderer(props: QuestionRendererProps) {
setActiveQuestionId,
selectedQuestions,
onSelectedQuestionsChange: handleSelectedQuestionsChange,
setSelectedLeafGroupId,
}), [
onEditQuestionClick,
projectId,
setActiveQuestionId,
setSelectedQuestionType,
selectedQuestions,
handleSelectedQuestionsChange,
setSelectedLeafGroupId,
]);

return (
Expand Down Expand Up @@ -230,6 +234,7 @@ function QuestionListRenderer(props: QuestionRendererProps) {
level={level + 1}
handleQuestionAdd={handleQuestionAdd}
addQuestionPaneShown={addQuestionPaneShown}
setSelectedLeafGroupId={setSelectedLeafGroupId}
/>
)}
</ExpandableContainer>
Expand All @@ -249,6 +254,7 @@ interface Props{
handleQuestionAdd: (groupId: string) => void;
addQuestionPaneShown: boolean;
selectedGroups: string[];
setSelectedLeafGroupId: React.Dispatch<React.SetStateAction<string | undefined>>;
}

function QuestionList(props: Props) {
Expand All @@ -263,6 +269,7 @@ function QuestionList(props: Props) {
level,
handleQuestionAdd,
addQuestionPaneShown,
setSelectedLeafGroupId,
} = props;

const questionListRendererParams = useCallback((_: string, datum: TocItem) => ({
Expand All @@ -276,6 +283,7 @@ function QuestionList(props: Props) {
level,
handleQuestionAdd,
addQuestionPaneShown,
setSelectedLeafGroupId,
}), [
projectId,
questionnaireId,
Expand All @@ -286,6 +294,7 @@ function QuestionList(props: Props) {
level,
addQuestionPaneShown,
handleQuestionAdd,
setSelectedLeafGroupId,
]);

const finalNodes = useMemo(() => (
Expand Down Expand Up @@ -324,6 +333,7 @@ function QuestionList(props: Props) {
handleQuestionAdd={handleQuestionAdd}
addQuestionPaneShown={addQuestionPaneShown}
selectedGroups={selectedGroups}
setSelectedLeafGroupId={setSelectedLeafGroupId}
/>
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/views/QuestionnaireEdit/QuestionPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
GrDrag,
} from 'react-icons/gr';
import {
isNotDefined,
isDefined,
} from '@togglecorp/fujs';
import {
Expand Down Expand Up @@ -43,6 +44,7 @@ interface QuestionProps {
setActiveQuestionId: React.Dispatch<React.SetStateAction<string | undefined>>;
selectedQuestions: string[] | undefined;
onSelectedQuestionsChange: (val: boolean, id: string) => void;
setSelectedLeafGroupId : React.Dispatch<React.SetStateAction<string | undefined>>;
attributes?: Attributes;
listeners?: Listeners;
}
Expand All @@ -55,20 +57,26 @@ function QuestionPreview(props: QuestionProps) {
setActiveQuestionId,
selectedQuestions,
onSelectedQuestionsChange,
setSelectedLeafGroupId,
projectId,
attributes,
listeners,
} = props;

const handleEditQuestionClick = useCallback((val: string) => {
if (isNotDefined(question.leafGroupId)) {
return;
}
showAddQuestionPane();
setSelectedQuestionType(question.type);
setActiveQuestionId(val);
setSelectedLeafGroupId(question.leafGroupId);
}, [
showAddQuestionPane,
setSelectedQuestionType,
question.type,
setActiveQuestionId,
setSelectedLeafGroupId,
question,
]);

return (
Expand Down
13 changes: 12 additions & 1 deletion src/views/QuestionnaireEdit/RankQuestionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TextInput,
Button,
useAlert,
Checkbox,
} from '@the-deep/deep-ui';
import {
gql,
Expand Down Expand Up @@ -97,7 +98,7 @@ type FormSchema = ObjectSchema<FormType>;
type FormSchemaFields = ReturnType<FormSchema['fields']>;

const schema: FormSchema = {
fields: () : FormSchemaFields => ({
fields: (): FormSchemaFields => ({
name: {
required: true,
requiredValidation: requiredStringCondition,
Expand All @@ -123,6 +124,9 @@ const schema: FormSchema = {
requiredValidation: requiredStringCondition,
},
hint: {},
required: {
defaultValue: false,
},
}),
};

Expand Down Expand Up @@ -195,6 +199,7 @@ function RankQuestionForm(props: Props) {
label: questionResponse?.label,
leafGroup: questionResponse?.leafGroupId,
hint: questionResponse?.hint,
required: questionResponse?.required,
choiceCollection: questionResponse?.choiceCollection?.id,
});
const choiceCollection = questionResponse?.choiceCollection;
Expand Down Expand Up @@ -356,6 +361,12 @@ function RankQuestionForm(props: Props) {
disabled
/>
</div>
<Checkbox
name="required"
label="Make question mandatory"
onChange={setFieldValue}
value={formValue.required}
/>
<Button
name={undefined}
className={styles.button}
Expand Down
Loading
Loading