@omniumretail/component-library 1.1.75 → 1.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.1.75",
3
+ "version": "1.1.77",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -46,6 +46,7 @@ const Template: Story<any> = (args) => {
46
46
  "IsNumeric": false,
47
47
  "HasGrade": false,
48
48
  "IsEmphasis": false,
49
+ "IsMultipleChoise": true,
49
50
  "State": "Draft",
50
51
  "Grade": 0,
51
52
  "Options": [
@@ -75,6 +76,7 @@ const Template: Story<any> = (args) => {
75
76
  "IsNumeric": false,
76
77
  "HasGrade": false,
77
78
  "IsEmphasis": false,
79
+ "IsMultipleChoise": true,
78
80
  "State": "Draft",
79
81
  "Grade": 0,
80
82
  "Options": [
@@ -104,6 +106,7 @@ const Template: Story<any> = (args) => {
104
106
  "IsNumeric": false,
105
107
  "HasGrade": false,
106
108
  "IsEmphasis": false,
109
+ "IsMultipleChoise": false,
107
110
  "State": "Finished",
108
111
  "Grade": 0,
109
112
  "Options": [
@@ -127,13 +130,7 @@ const Template: Story<any> = (args) => {
127
130
  }
128
131
  ]
129
132
 
130
- const answerTypeOptions = getAnswerTypeOptions?.map((answerType) => ({
131
- value: answerType?.Id,
132
- label: answerType?.Name
133
- }));
134
-
135
-
136
- return <Category {...args} chooseResponse serverReadyData={setServerData} responseTypeOptions={answerTypeOptions} hasHeader data={[]}></Category>
133
+ return <Category {...args} chooseResponse serverReadyData={setServerData} responseTypeOptions={getAnswerTypeOptions} hasHeader data={[]}></Category>
137
134
  };
138
135
 
139
136
  export const Primary = Template.bind({});
@@ -38,7 +38,7 @@ const Template: Story<any> = (args) => {
38
38
  };
39
39
 
40
40
  useEffect(() => {
41
- // console.log(serverData);
41
+ console.log(serverData);
42
42
  }, [serverData])
43
43
 
44
44
  return (
@@ -167,7 +167,7 @@ Primary.args = {
167
167
  "Subject": "This is a Subject",
168
168
  "Description": "This is a description",
169
169
  "Grade": "50",
170
- "Answer": null
170
+ "Answer": []
171
171
  },
172
172
  {
173
173
  "Id": "35562A64-A24B-425A-A345-560238CA2468",
@@ -175,7 +175,8 @@ Primary.args = {
175
175
  "Subject": "This is a Subject",
176
176
  "Description": "This is a description",
177
177
  "Grade": "25",
178
- "Answer": null
178
+ "Answer": ["1"],
179
+ "IsMultipleChoise": false
179
180
  },
180
181
  {
181
182
  "Id": "35562A64-A24B-425A-A345-560238CA2468",
@@ -183,7 +184,8 @@ Primary.args = {
183
184
  "Subject": "This is a Subject",
184
185
  "Description": "This is a description",
185
186
  "Grade": "25",
186
- "Answer": null
187
+ "Answer": [],
188
+ "IsMultipleChoise": true
187
189
  }
188
190
  ]
189
191
  }
@@ -233,7 +235,7 @@ Primary.args = {
233
235
  "Id": "97A06838-67F9-4726-BC36-719A0C797484",
234
236
  "CategoryId": "CATEGORYID3",
235
237
  "CategoryName": "Category 3",
236
- "OpenAnswer": true,
238
+ "OpenAnswer": false,
237
239
  "GeneralEvaluationLevel": 0,
238
240
  "Grade": "0",
239
241
  "Description": "This is a description",
@@ -245,7 +247,8 @@ Primary.args = {
245
247
  "Subject": "This is a Subject",
246
248
  "Description": "This is a description",
247
249
  "Grade": "0",
248
- "Answer": "dwjdiwjdiwjdi"
250
+ "Answer": "dwjdiwjdiwjdi",
251
+ "IsOpenAnswer": true
249
252
  },
250
253
  {
251
254
  "Id": "93862A64-A24B-425A-A345-560238CA2468",
@@ -253,7 +256,8 @@ Primary.args = {
253
256
  "Subject": "This is a Subject",
254
257
  "Description": "This is a description",
255
258
  "Grade": "0",
256
- "Answer": null
259
+ "Answer": null,
260
+ "IsMultipleChoise": true
257
261
  }
258
262
  ]
259
263
  }
@@ -16,7 +16,7 @@ interface CategoryResponse {
16
16
  onNextCategoryAvailabilityChange: (hasNext: boolean) => void;
17
17
  onPreviousCategoryAvailabilityChange: (hasPrevious: boolean) => void;
18
18
  selectYesNoOption?: any;
19
- addAction?: (questionId: string, questionAnswerId:string) => void;
19
+ addAction?: (questionId: string, questionAnswerId: string) => void;
20
20
  addButtons?: boolean;
21
21
  fileList?: React.Dispatch<React.SetStateAction<Record<string, UploadFile<any>[]>>>;
22
22
  };
@@ -84,15 +84,6 @@ const hasCategory = (currentKey: string, categories: Category[], direction: 'nex
84
84
  return !!category;
85
85
  };
86
86
 
87
- const getTitleWithQuestionCount = (category: any): string => {
88
- const questionCount = category?.Data?.Questions?.length;
89
- const answeredQuestions = category?.Data?.Questions?.filter((question: any) => question.Answer !== null && question.Answer !== undefined && question.Answer !== '').length;
90
-
91
- return questionCount
92
- ? `${category.Title} - ${answeredQuestions} / ${questionCount}`
93
- : category.Title;
94
- };
95
-
96
87
  export const CategoryResponse = React.forwardRef((props: CategoryResponse, ref) => {
97
88
  const { data } = props;
98
89
 
@@ -117,7 +108,8 @@ export const CategoryResponse = React.forwardRef((props: CategoryResponse, ref)
117
108
  Subject: question.Subject,
118
109
  Description: question.Description,
119
110
  Answer: question.Answer || "",
120
- Note: question.Note || ""
111
+ Note: question.Note || "",
112
+ IsMultipleChoise: question.IsMultipleChoise || false
121
113
  })),
122
114
  OpenAnswer: OpenAnswer,
123
115
  IsYesOrNo: IsYesOrNo
@@ -127,6 +119,16 @@ export const CategoryResponse = React.forwardRef((props: CategoryResponse, ref)
127
119
  form.setFieldsValue(initial);
128
120
  };
129
121
 
122
+ const getTitleWithQuestionCount = (category: any): string => {
123
+ const questionCount = category?.Data?.Questions?.length;
124
+ const answeredQuestions = category?.Data?.Questions?.filter
125
+ ((question: any) => question.Answer !== null && question.Answer !== undefined && question.Answer !== '' && question.Answer.length > 0).length;
126
+
127
+ return questionCount
128
+ ? `${category.Title} - ${answeredQuestions} / ${questionCount}`
129
+ : category.Title;
130
+ };
131
+
130
132
  const handleLabelClick = (category: any, index: number) => {
131
133
  setSelectedCategory(category);
132
134
  updateInitialValues(category.Data);
@@ -172,8 +174,15 @@ export const CategoryResponse = React.forwardRef((props: CategoryResponse, ref)
172
174
  const updatedQuestions = initialValues.Questions.map((question: any, index: number) => {
173
175
  return {
174
176
  ...question,
175
- Answer: values.Questions[index].Answer,
177
+ Answer: !props.addButtons
178
+ ? values.Questions[index].Answer
179
+ : Array.isArray(values.Questions[index].Answer)
180
+ ? values.Questions[index].Answer
181
+ : values.Questions[index].Answer
182
+ ? [values.Questions[index].Answer]
183
+ : [],
176
184
  Note: values.Questions[index].Note,
185
+ IsMultipleChoise: values.Questions[index].IsMultipleChoise,
177
186
  Files: fileLists[`${selectedCategory.Data.CategoryId}_${index}`] || [], // Include files in the form data
178
187
  };
179
188
  });
@@ -347,7 +356,7 @@ export const CategoryResponse = React.forwardRef((props: CategoryResponse, ref)
347
356
 
348
357
  <Button customClass={styles.actionsButtons} onClick={() => handleAddAction(question.QuestionId, question.Id)}>
349
358
  {t('components.categoryResponse.createAction')}
350
- </Button>
359
+ </Button>
351
360
  </div>
352
361
  </>
353
362
  }
@@ -371,6 +380,7 @@ export const CategoryResponse = React.forwardRef((props: CategoryResponse, ref)
371
380
  : evaluationOptions[selectedEvaluationOption]
372
381
  }
373
382
  // style={{ minWidth: '100%' }}
383
+ mode={form.getFieldValue(`Questions`)?.[index]?.IsMultipleChoise ? "multiple" : undefined}
374
384
  customClass={styles.selectAnswerStyle}
375
385
  />
376
386
  </Form.Item>
@@ -2,9 +2,10 @@ import { DeleteOutlined, HolderOutlined, InfoCircleOutlined } from '@ant-design/
2
2
  import { Checkbox, ColorPicker, Form, Input, Space } from 'antd';
3
3
  import { t } from 'i18next';
4
4
  import styles from './styles.module.scss';
5
- import { useState } from 'react';
5
+ import { useContext, useState } from 'react';
6
6
  import { Select } from 'antd';
7
7
  import classnames from 'classnames';
8
+ import { FieldContext } from 'rc-field-form';
8
9
 
9
10
  export const SingleQuestion = ({
10
11
  key,
@@ -24,6 +25,19 @@ export const SingleQuestion = ({
24
25
  const [emphasisCheckbox, setEmphasisCheckbox] = useState<boolean>(false);
25
26
  const [multipleChoiseCheckbox, setMultipleChoiseCheckbox] = useState<boolean>(false);
26
27
 
28
+ const formContext = useContext(FieldContext);
29
+
30
+ const filteredIds = responseTypeOptions
31
+ .filter((item: { IsMultipleChoise: any; }) => item.IsMultipleChoise)
32
+ .map((item: { Id: any; }) => item.Id);
33
+
34
+ const answerTypeOptions = responseTypeOptions?.map((answerType: any) => ({
35
+ value: answerType?.Id,
36
+ label: answerType?.Name
37
+ }));
38
+
39
+ console.log(filteredIds);
40
+
27
41
  const onCheckboxMultipeChoiseHandler = (checked: boolean) => {
28
42
  setMultipleChoiseCheckbox(checked);
29
43
  handleChanges();
@@ -145,7 +159,8 @@ export const SingleQuestion = ({
145
159
  <span>{t('components.category.emphasisAnswer')}</span>
146
160
  </div>
147
161
 
148
- <div className={styles.checkboxContainer}>
162
+ {filteredIds.includes(formContext.getFieldsValue().questions?.[name]?.responseType) &&
163
+ < div className={styles.checkboxContainer}>
149
164
  <Form.Item
150
165
  {...restField}
151
166
  name={[name, 'multipleChoise']}
@@ -156,6 +171,8 @@ export const SingleQuestion = ({
156
171
 
157
172
  <span>{t('components.category.multipleChoise')}</span>
158
173
  </div>
174
+ }
175
+
159
176
  </>
160
177
  }
161
178
 
@@ -166,7 +183,7 @@ export const SingleQuestion = ({
166
183
  rules={[{ required: true, message: t('components.category.errorResponseType')! }]}
167
184
  >
168
185
  <Select
169
- options={responseTypeOptions}
186
+ options={answerTypeOptions}
170
187
  onBlur={handleChanges}
171
188
  className={styles.selectResponseType}
172
189
  />
@@ -177,7 +194,8 @@ export const SingleQuestion = ({
177
194
  </div>
178
195
  }
179
196
 
180
- {responseTypeComponent &&
197
+ {
198
+ responseTypeComponent &&
181
199
  <div className={styles.questionFooter}>
182
200
  <div />
183
201
 
@@ -218,7 +236,7 @@ export const SingleQuestion = ({
218
236
  </div>
219
237
  </div>
220
238
  }
221
- </Space>
222
- </div>
239
+ </Space >
240
+ </div >
223
241
  );
224
242
  };