@elice/material-survey 1.220803.0
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/README.md +3 -0
- package/cjs/components/material-survey/MaterialSurvey.d.ts +4 -0
- package/cjs/components/material-survey/MaterialSurvey.i18n.d.ts +16 -0
- package/cjs/components/material-survey/MaterialSurvey.i18n.js +37 -0
- package/cjs/components/material-survey/MaterialSurvey.js +109 -0
- package/cjs/components/material-survey/MaterialSurveyError.d.ts +3 -0
- package/cjs/components/material-survey/MaterialSurveyInfo.d.ts +3 -0
- package/cjs/components/material-survey/MaterialSurveyInfo.js +73 -0
- package/cjs/components/material-survey/MaterialSurveySelectMultiple.d.ts +3 -0
- package/cjs/components/material-survey/MaterialSurveySelectMultiple.js +184 -0
- package/cjs/components/material-survey/MaterialSurveySelectOne.d.ts +3 -0
- package/cjs/components/material-survey/MaterialSurveySelectOne.js +164 -0
- package/cjs/components/material-survey/MaterialSurveyShimmer.d.ts +3 -0
- package/cjs/components/material-survey/MaterialSurveyShimmer.js +61 -0
- package/cjs/components/material-survey/MaterialSurveyText.d.ts +3 -0
- package/cjs/components/material-survey/MaterialSurveyText.js +159 -0
- package/cjs/components/material-survey/SurveyResultBadge.d.ts +7 -0
- package/cjs/components/material-survey/SurveyResultBadge.js +32 -0
- package/cjs/components/material-survey/SurveySubmitStatusText.d.ts +7 -0
- package/cjs/components/material-survey/SurveySubmitStatusText.js +38 -0
- package/cjs/components/material-survey/context/MaterialSurveyContext.d.ts +31 -0
- package/cjs/components/material-survey/context/MaterialSurveyContext.js +134 -0
- package/cjs/components/material-survey/index.d.ts +3 -0
- package/cjs/components/material-survey-edit/MaterialSurveyEdit.d.ts +25 -0
- package/cjs/components/material-survey-edit/MaterialSurveyEdit.js +91 -0
- package/cjs/components/material-survey-edit/MaterialSurveyEditContent.d.ts +3 -0
- package/cjs/components/material-survey-edit/MaterialSurveyEditContent.js +235 -0
- package/cjs/components/material-survey-edit/MaterialSurveyEditOptionSelect.d.ts +3 -0
- package/cjs/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +132 -0
- package/cjs/components/material-survey-edit/context.d.ts +6 -0
- package/cjs/components/material-survey-edit/context.js +15 -0
- package/cjs/components/material-survey-edit/index.d.ts +2 -0
- package/cjs/components/material-survey-edit/locales.d.ts +20 -0
- package/cjs/components/material-survey-edit/locales.js +45 -0
- package/cjs/components/material-survey-edit/utils/editValue.d.ts +19 -0
- package/cjs/components/material-survey-edit/utils/editValue.js +46 -0
- package/cjs/components/material-survey-edit/utils/randomId.d.ts +4 -0
- package/cjs/components/material-survey-edit/utils/randomId.js +12 -0
- package/cjs/components/shared/StyledMarkdown.d.ts +3 -0
- package/cjs/components/shared/StyledMarkdown.js +14 -0
- package/cjs/components/shared/SurveyContentBox.d.ts +15 -0
- package/cjs/components/shared/SurveyContentBox.js +108 -0
- package/cjs/components/shared/index.d.ts +4 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +26 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +42 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +226 -0
- package/cjs/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/cjs/components/shared/question-radio/QuestionRadio.js +26 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +42 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +187 -0
- package/cjs/helpers/index.d.ts +22 -0
- package/cjs/helpers/index.js +26 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +21 -0
- package/es/components/material-survey/MaterialSurvey.d.ts +4 -0
- package/es/components/material-survey/MaterialSurvey.i18n.d.ts +16 -0
- package/es/components/material-survey/MaterialSurvey.i18n.js +32 -0
- package/es/components/material-survey/MaterialSurvey.js +101 -0
- package/es/components/material-survey/MaterialSurveyError.d.ts +3 -0
- package/es/components/material-survey/MaterialSurveyInfo.d.ts +3 -0
- package/es/components/material-survey/MaterialSurveyInfo.js +67 -0
- package/es/components/material-survey/MaterialSurveySelectMultiple.d.ts +3 -0
- package/es/components/material-survey/MaterialSurveySelectMultiple.js +178 -0
- package/es/components/material-survey/MaterialSurveySelectOne.d.ts +3 -0
- package/es/components/material-survey/MaterialSurveySelectOne.js +158 -0
- package/es/components/material-survey/MaterialSurveyShimmer.d.ts +3 -0
- package/es/components/material-survey/MaterialSurveyShimmer.js +54 -0
- package/es/components/material-survey/MaterialSurveyText.d.ts +3 -0
- package/es/components/material-survey/MaterialSurveyText.js +152 -0
- package/es/components/material-survey/SurveyResultBadge.d.ts +7 -0
- package/es/components/material-survey/SurveyResultBadge.js +26 -0
- package/es/components/material-survey/SurveySubmitStatusText.d.ts +7 -0
- package/es/components/material-survey/SurveySubmitStatusText.js +32 -0
- package/es/components/material-survey/context/MaterialSurveyContext.d.ts +31 -0
- package/es/components/material-survey/context/MaterialSurveyContext.js +124 -0
- package/es/components/material-survey/index.d.ts +3 -0
- package/es/components/material-survey-edit/MaterialSurveyEdit.d.ts +25 -0
- package/es/components/material-survey-edit/MaterialSurveyEdit.js +86 -0
- package/es/components/material-survey-edit/MaterialSurveyEditContent.d.ts +3 -0
- package/es/components/material-survey-edit/MaterialSurveyEditContent.js +228 -0
- package/es/components/material-survey-edit/MaterialSurveyEditOptionSelect.d.ts +3 -0
- package/es/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +125 -0
- package/es/components/material-survey-edit/context.d.ts +6 -0
- package/es/components/material-survey-edit/context.js +6 -0
- package/es/components/material-survey-edit/index.d.ts +2 -0
- package/es/components/material-survey-edit/locales.d.ts +20 -0
- package/es/components/material-survey-edit/locales.js +40 -0
- package/es/components/material-survey-edit/utils/editValue.d.ts +19 -0
- package/es/components/material-survey-edit/utils/editValue.js +41 -0
- package/es/components/material-survey-edit/utils/randomId.d.ts +4 -0
- package/es/components/material-survey-edit/utils/randomId.js +8 -0
- package/es/components/shared/StyledMarkdown.d.ts +3 -0
- package/es/components/shared/StyledMarkdown.js +8 -0
- package/es/components/shared/SurveyContentBox.d.ts +15 -0
- package/es/components/shared/SurveyContentBox.js +98 -0
- package/es/components/shared/index.d.ts +4 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +19 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +33 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +219 -0
- package/es/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/es/components/shared/question-radio/QuestionRadio.js +19 -0
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioContext.js +33 -0
- package/es/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioOption.js +180 -0
- package/es/helpers/index.d.ts +22 -0
- package/es/helpers/index.js +21 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +7 -0
- package/package.json +71 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { getOrgMaterialSurveyResponseGet, getOrgMaterialSurveyResponseList, postOrgMaterialSurveyResponseAdd } from '@elice/api-client';
|
|
4
|
+
import { checkUserLectureTestEnded } from '../../helpers/index.js';
|
|
5
|
+
import QuestionRadio from '../shared/question-radio/QuestionRadio.js';
|
|
6
|
+
import QuestionRadioOption from '../shared/question-radio/QuestionRadioOption.js';
|
|
7
|
+
import '../shared/question-checkbox/QuestionCheckbox.js';
|
|
8
|
+
import '../shared/question-checkbox/QuestionCheckboxOption.js';
|
|
9
|
+
import StyledMarkdown from '../shared/StyledMarkdown.js';
|
|
10
|
+
import SurveyContentBox from '../shared/SurveyContentBox.js';
|
|
11
|
+
import { useMaterialSurveyState, useMaterialSurveyDispatch } from './context/MaterialSurveyContext.js';
|
|
12
|
+
import SurveyResultBadge from './SurveyResultBadge.js';
|
|
13
|
+
import SurveySubmitStatusText from './SurveySubmitStatusText.js';
|
|
14
|
+
|
|
15
|
+
const MaterialSurveySelectOne = () => {
|
|
16
|
+
// context
|
|
17
|
+
const {
|
|
18
|
+
course,
|
|
19
|
+
lecture,
|
|
20
|
+
materialSurvey,
|
|
21
|
+
userId
|
|
22
|
+
} = useMaterialSurveyState();
|
|
23
|
+
const {
|
|
24
|
+
onSubmit,
|
|
25
|
+
onNext,
|
|
26
|
+
refreshOrgMaterialSurvey
|
|
27
|
+
} = useMaterialSurveyDispatch(); // state
|
|
28
|
+
|
|
29
|
+
const intl = useIntl();
|
|
30
|
+
const [selectedAnswer, setSelectedAnswer] = React.useState();
|
|
31
|
+
const [materialSurveyResponse, setMaterialSurveyResponse] = React.useState();
|
|
32
|
+
const [submitStatus, setSubmitStatus] = React.useState('idle'); // survey response fetcher
|
|
33
|
+
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
const {
|
|
38
|
+
signal
|
|
39
|
+
} = controller;
|
|
40
|
+
getOrgMaterialSurveyResponseGet({
|
|
41
|
+
surveyResponseId: materialSurvey.lastSurveyResponseId
|
|
42
|
+
}, {
|
|
43
|
+
signal
|
|
44
|
+
}).then(response => {
|
|
45
|
+
setMaterialSurveyResponse(response.surveyResponse);
|
|
46
|
+
setSelectedAnswer(typeof response.surveyResponse.answers[0] === 'string' ? undefined : response.surveyResponse.answers[0][0]);
|
|
47
|
+
}).catch(error => {
|
|
48
|
+
console.error(error);
|
|
49
|
+
});
|
|
50
|
+
return () => controller.abort();
|
|
51
|
+
}
|
|
52
|
+
}, [materialSurvey, userId]); // survey response fetcher
|
|
53
|
+
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
if (userId && materialSurvey) {
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const {
|
|
58
|
+
signal
|
|
59
|
+
} = controller;
|
|
60
|
+
getOrgMaterialSurveyResponseList({
|
|
61
|
+
materialSurveyId: materialSurvey.id,
|
|
62
|
+
filterUserIds: [userId],
|
|
63
|
+
isContainOnlyLast: true,
|
|
64
|
+
isIncludeAnswer: true,
|
|
65
|
+
offset: 0,
|
|
66
|
+
count: 1
|
|
67
|
+
}, {
|
|
68
|
+
signal
|
|
69
|
+
}).then(response => {
|
|
70
|
+
var _a;
|
|
71
|
+
|
|
72
|
+
const surveyResponse = response.surveyResponses[0];
|
|
73
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
74
|
+
setSelectedAnswer(typeof (surveyResponse === null || surveyResponse === void 0 ? void 0 : surveyResponse.answers[0]) === 'string' ? undefined : (_a = surveyResponse === null || surveyResponse === void 0 ? void 0 : surveyResponse.answers[0][0]) !== null && _a !== void 0 ? _a : undefined);
|
|
75
|
+
}).catch(error => {
|
|
76
|
+
console.error(error);
|
|
77
|
+
});
|
|
78
|
+
return () => controller.abort();
|
|
79
|
+
}
|
|
80
|
+
}, [materialSurvey, userId]); // submit handler
|
|
81
|
+
|
|
82
|
+
const handleSubmit = async () => {
|
|
83
|
+
if (!materialSurvey) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setSubmitStatus('pending');
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const {
|
|
91
|
+
surveyResponseId
|
|
92
|
+
} = await postOrgMaterialSurveyResponseAdd({
|
|
93
|
+
materialSurveyId: materialSurvey.id,
|
|
94
|
+
answers: [[selectedAnswer]]
|
|
95
|
+
});
|
|
96
|
+
const {
|
|
97
|
+
surveyResponse
|
|
98
|
+
} = await getOrgMaterialSurveyResponseGet({
|
|
99
|
+
surveyResponseId
|
|
100
|
+
});
|
|
101
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
102
|
+
void refreshOrgMaterialSurvey();
|
|
103
|
+
onSubmit(true);
|
|
104
|
+
setSubmitStatus('resolved');
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error(error);
|
|
107
|
+
onSubmit(false);
|
|
108
|
+
setSubmitStatus('rejected');
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return React.createElement(SurveyContentBox, {
|
|
113
|
+
title: intl.formatMessage({
|
|
114
|
+
id: 'materialSurvey.myAnswer'
|
|
115
|
+
}),
|
|
116
|
+
onNext: onNext,
|
|
117
|
+
submitStatus: React.createElement(SurveySubmitStatusText, {
|
|
118
|
+
status: submitStatus
|
|
119
|
+
}),
|
|
120
|
+
submitResult: React.createElement(SurveyResultBadge, {
|
|
121
|
+
materialSurveyResponse: materialSurveyResponse
|
|
122
|
+
}),
|
|
123
|
+
footerActions: [{
|
|
124
|
+
border: true,
|
|
125
|
+
disabled: selectedAnswer === undefined || checkUserLectureTestEnded(lecture) || !!userId,
|
|
126
|
+
loading: submitStatus === 'pending',
|
|
127
|
+
tabIndex: 0,
|
|
128
|
+
transparent: false,
|
|
129
|
+
role: 'primary',
|
|
130
|
+
onClick: handleSubmit,
|
|
131
|
+
children: intl.formatMessage({
|
|
132
|
+
id: 'materialSurvey.submit'
|
|
133
|
+
})
|
|
134
|
+
}]
|
|
135
|
+
}, React.createElement(QuestionRadio, {
|
|
136
|
+
selectedValue: selectedAnswer,
|
|
137
|
+
onSelect: index => {
|
|
138
|
+
if (checkUserLectureTestEnded(lecture) || !!userId) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setSelectedAnswer(index);
|
|
143
|
+
},
|
|
144
|
+
disabled: submitStatus === 'pending' || checkUserLectureTestEnded(lecture) || !!userId
|
|
145
|
+
}, (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.questionInfoList[0].optionInfo) ? materialSurvey.questionInfoList[0].optionInfo.map((option, index) => {
|
|
146
|
+
return React.createElement(QuestionRadioOption, {
|
|
147
|
+
key: index,
|
|
148
|
+
value: index
|
|
149
|
+
}, (course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInSurveyOptions) ? React.createElement(StyledMarkdown, {
|
|
150
|
+
dark: false,
|
|
151
|
+
children: option,
|
|
152
|
+
paddingx: 0,
|
|
153
|
+
paddingy: 0
|
|
154
|
+
}) : option);
|
|
155
|
+
}) : null));
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export { MaterialSurveySelectOne as default };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Shimmer, Vspace } from '@elice/blocks';
|
|
3
|
+
import { base } from '@elice/design-tokens';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
import { useMaterialSurveyState } from './context/MaterialSurveyContext.js';
|
|
6
|
+
|
|
7
|
+
const StyledShimmer = styled.div.withConfig({
|
|
8
|
+
componentId: "sc-1gtcofd-0"
|
|
9
|
+
})(["display:flex;flex-direction:column;border-radius:", ";overflow:hidden;width:100%;"], ({
|
|
10
|
+
vertical
|
|
11
|
+
}) => vertical ? '0' : '8px');
|
|
12
|
+
const StyledShimmerHeader = styled.div.withConfig({
|
|
13
|
+
componentId: "sc-1gtcofd-1"
|
|
14
|
+
})(["display:flex;justify-content:space-between;background-color:", ";padding:1rem 1.5rem;height:3.5rem;"], base.color.navy6);
|
|
15
|
+
const StyledShimmerBody = styled.div.withConfig({
|
|
16
|
+
componentId: "sc-1gtcofd-2"
|
|
17
|
+
})(["padding:1.5rem;background-color:", ";overflow-y:auto;height:100%;"], base.color.navy7);
|
|
18
|
+
|
|
19
|
+
const MaterialSurveyShimmer = () => {
|
|
20
|
+
const {
|
|
21
|
+
vertical
|
|
22
|
+
} = useMaterialSurveyState();
|
|
23
|
+
return React.createElement(StyledShimmer, {
|
|
24
|
+
vertical: vertical
|
|
25
|
+
}, React.createElement(StyledShimmerHeader, null), React.createElement(StyledShimmerBody, null, React.createElement(Shimmer, {
|
|
26
|
+
dark: true,
|
|
27
|
+
borderRadius: '4px',
|
|
28
|
+
width: "80%",
|
|
29
|
+
height: '40px'
|
|
30
|
+
}), React.createElement(Vspace, {
|
|
31
|
+
height: 1
|
|
32
|
+
}), React.createElement(Shimmer, {
|
|
33
|
+
dark: true,
|
|
34
|
+
borderRadius: '4px',
|
|
35
|
+
width: "100%",
|
|
36
|
+
height: '40px'
|
|
37
|
+
}), React.createElement(Vspace, {
|
|
38
|
+
height: 1
|
|
39
|
+
}), React.createElement(Shimmer, {
|
|
40
|
+
dark: true,
|
|
41
|
+
borderRadius: '4px',
|
|
42
|
+
width: "100%",
|
|
43
|
+
height: '40px'
|
|
44
|
+
}), React.createElement(Vspace, {
|
|
45
|
+
height: 1
|
|
46
|
+
}), React.createElement(Shimmer, {
|
|
47
|
+
dark: true,
|
|
48
|
+
borderRadius: '4px',
|
|
49
|
+
width: "100%",
|
|
50
|
+
height: '40px'
|
|
51
|
+
})));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { MaterialSurveyShimmer as default };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { getOrgMaterialSurveyResponseGet, getOrgMaterialSurveyResponseList, postOrgMaterialSurveyResponseAdd } from '@elice/api-client';
|
|
4
|
+
import { base } from '@elice/design-tokens';
|
|
5
|
+
import styled from 'styled-components';
|
|
6
|
+
import { checkUserLectureTestEnded } from '../../helpers/index.js';
|
|
7
|
+
import SurveyContentBox from '../shared/SurveyContentBox.js';
|
|
8
|
+
import { useMaterialSurveyState, useMaterialSurveyDispatch } from './context/MaterialSurveyContext.js';
|
|
9
|
+
import SurveyResultBadge from './SurveyResultBadge.js';
|
|
10
|
+
import SurveySubmitStatusText from './SurveySubmitStatusText.js';
|
|
11
|
+
|
|
12
|
+
const StyledTextarea = styled.textarea.withConfig({
|
|
13
|
+
componentId: "sc-16tkulg-0"
|
|
14
|
+
})(["min-height:12rem;width:100%;padding:1rem 1.375rem;font-size:1rem;color:", ";border-radius:4px;resize:vertical;line-height:1.5rem;outline:none;background-color:", ";&::placeholder{color:", ";}&:hover{cursor:", ";}"], base.color.navy2, base.color.navy5, base.color.navy2, ({
|
|
15
|
+
disabled
|
|
16
|
+
}) => disabled ? 'not-allowed' : 'text');
|
|
17
|
+
|
|
18
|
+
const MaterialSurveyText = () => {
|
|
19
|
+
// context
|
|
20
|
+
const {
|
|
21
|
+
lecture,
|
|
22
|
+
materialSurvey,
|
|
23
|
+
userId
|
|
24
|
+
} = useMaterialSurveyState();
|
|
25
|
+
const {
|
|
26
|
+
onSubmit,
|
|
27
|
+
onNext,
|
|
28
|
+
refreshOrgMaterialSurvey
|
|
29
|
+
} = useMaterialSurveyDispatch(); // state
|
|
30
|
+
|
|
31
|
+
const intl = useIntl();
|
|
32
|
+
const [materialSurveyResponse, setMaterialSurveyResponse] = React.useState();
|
|
33
|
+
const [submitStatus, setSubmitStatus] = React.useState('idle');
|
|
34
|
+
const [answer, setAnswer] = React.useState(''); // survey response fetcher
|
|
35
|
+
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const {
|
|
40
|
+
signal
|
|
41
|
+
} = controller;
|
|
42
|
+
getOrgMaterialSurveyResponseGet({
|
|
43
|
+
surveyResponseId: materialSurvey.lastSurveyResponseId
|
|
44
|
+
}, {
|
|
45
|
+
signal
|
|
46
|
+
}).then(response => {
|
|
47
|
+
setMaterialSurveyResponse(response.surveyResponse);
|
|
48
|
+
setAnswer(response.surveyResponse.answers[0]);
|
|
49
|
+
}).catch(error => {
|
|
50
|
+
console.error(error);
|
|
51
|
+
});
|
|
52
|
+
return () => controller.abort();
|
|
53
|
+
}
|
|
54
|
+
}, [materialSurvey, userId]); // survey response fetcher
|
|
55
|
+
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
if (userId && materialSurvey) {
|
|
58
|
+
const controller = new AbortController();
|
|
59
|
+
const {
|
|
60
|
+
signal
|
|
61
|
+
} = controller;
|
|
62
|
+
getOrgMaterialSurveyResponseList({
|
|
63
|
+
materialSurveyId: materialSurvey.id,
|
|
64
|
+
filterUserIds: [userId],
|
|
65
|
+
isContainOnlyLast: true,
|
|
66
|
+
isIncludeAnswer: true,
|
|
67
|
+
offset: 0,
|
|
68
|
+
count: 1
|
|
69
|
+
}, {
|
|
70
|
+
signal
|
|
71
|
+
}).then(response => {
|
|
72
|
+
const surveyResponse = response.surveyResponses[0];
|
|
73
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
74
|
+
setAnswer(typeof (surveyResponse === null || surveyResponse === void 0 ? void 0 : surveyResponse.answers[0]) === 'string' ? surveyResponse.answers[0] : '');
|
|
75
|
+
}).catch(error => {
|
|
76
|
+
console.error(error);
|
|
77
|
+
});
|
|
78
|
+
return () => controller.abort();
|
|
79
|
+
}
|
|
80
|
+
}, [materialSurvey, userId]); // submit handler
|
|
81
|
+
|
|
82
|
+
const handleSubmit = async () => {
|
|
83
|
+
if (!materialSurvey) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setSubmitStatus('pending');
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const {
|
|
91
|
+
surveyResponseId
|
|
92
|
+
} = await postOrgMaterialSurveyResponseAdd({
|
|
93
|
+
materialSurveyId: materialSurvey.id,
|
|
94
|
+
answers: [answer]
|
|
95
|
+
});
|
|
96
|
+
const {
|
|
97
|
+
surveyResponse
|
|
98
|
+
} = await getOrgMaterialSurveyResponseGet({
|
|
99
|
+
surveyResponseId
|
|
100
|
+
});
|
|
101
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
102
|
+
void refreshOrgMaterialSurvey();
|
|
103
|
+
onSubmit(true);
|
|
104
|
+
setSubmitStatus('resolved');
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error(error);
|
|
107
|
+
onSubmit(false);
|
|
108
|
+
setSubmitStatus('rejected');
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const commonProps = {
|
|
113
|
+
type: 'text',
|
|
114
|
+
autoFocus: answer.length === 0,
|
|
115
|
+
disabled: submitStatus === 'pending' || checkUserLectureTestEnded(lecture) || !!userId,
|
|
116
|
+
placeholder: intl.formatMessage({
|
|
117
|
+
id: 'materialSurvey.text.placeholder'
|
|
118
|
+
}),
|
|
119
|
+
value: answer,
|
|
120
|
+
onChange: e => {
|
|
121
|
+
setAnswer(e.target.value);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return React.createElement(SurveyContentBox, {
|
|
125
|
+
title: intl.formatMessage({
|
|
126
|
+
id: 'materialSurvey.myAnswer'
|
|
127
|
+
}),
|
|
128
|
+
onNext: onNext,
|
|
129
|
+
submitResult: React.createElement(SurveyResultBadge, {
|
|
130
|
+
materialSurveyResponse: materialSurveyResponse
|
|
131
|
+
}),
|
|
132
|
+
submitStatus: React.createElement(SurveySubmitStatusText, {
|
|
133
|
+
status: submitStatus
|
|
134
|
+
}),
|
|
135
|
+
footerActions: [{
|
|
136
|
+
border: true,
|
|
137
|
+
children: intl.formatMessage({
|
|
138
|
+
id: 'materialSurvey.submit'
|
|
139
|
+
}),
|
|
140
|
+
disabled: answer.length === 0 || checkUserLectureTestEnded(lecture) || !!userId,
|
|
141
|
+
loading: submitStatus === 'pending',
|
|
142
|
+
tabIndex: 0,
|
|
143
|
+
transparent: false,
|
|
144
|
+
role: 'primary',
|
|
145
|
+
onClick: handleSubmit
|
|
146
|
+
}]
|
|
147
|
+
}, React.createElement(StyledTextarea, Object.assign({
|
|
148
|
+
id: "survey-text-answer"
|
|
149
|
+
}, commonProps)));
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { MaterialSurveyText as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { GetOrgMaterialSurveyResponseGetResponses } from '@elice/types';
|
|
3
|
+
interface SurveyResultStatusProps {
|
|
4
|
+
materialSurveyResponse?: GetOrgMaterialSurveyResponseGetResponses['surveyResponse'];
|
|
5
|
+
}
|
|
6
|
+
declare const SurveyResultBadge: React.FC<SurveyResultStatusProps>;
|
|
7
|
+
export default SurveyResultBadge;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { BadgeNext } from '@elice/blocks';
|
|
4
|
+
import { getSurveyResultStatus, SurveyResultStatus } from '../../helpers/index.js';
|
|
5
|
+
|
|
6
|
+
const SurveyResultBadge = ({
|
|
7
|
+
materialSurveyResponse
|
|
8
|
+
}) => {
|
|
9
|
+
const intl = useIntl();
|
|
10
|
+
const status = React.useMemo(() => getSurveyResultStatus(materialSurveyResponse), [materialSurveyResponse]);
|
|
11
|
+
|
|
12
|
+
switch (status) {
|
|
13
|
+
case SurveyResultStatus.Submitted:
|
|
14
|
+
return React.createElement(BadgeNext, {
|
|
15
|
+
type: "quiet",
|
|
16
|
+
role: "primary"
|
|
17
|
+
}, intl.formatMessage({
|
|
18
|
+
id: 'materialSurvey.resultStatus.submitted'
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
default:
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { SurveyResultBadge as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { APIStatus } from '@elice/material-shared-types';
|
|
3
|
+
interface SurveySubmitStatusTextProps {
|
|
4
|
+
status: APIStatus;
|
|
5
|
+
}
|
|
6
|
+
declare const SurveySubmitStatusText: React.FC<SurveySubmitStatusTextProps>;
|
|
7
|
+
export default SurveySubmitStatusText;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { StatusText } from '@elice/blocks';
|
|
4
|
+
|
|
5
|
+
const SurveySubmitStatusText = ({
|
|
6
|
+
status
|
|
7
|
+
}) => {
|
|
8
|
+
const intl = useIntl();
|
|
9
|
+
|
|
10
|
+
switch (status) {
|
|
11
|
+
case 'resolved':
|
|
12
|
+
return React.createElement(StatusText, {
|
|
13
|
+
role: "success",
|
|
14
|
+
size: "small"
|
|
15
|
+
}, intl.formatMessage({
|
|
16
|
+
id: 'materialSurvey.submitStatus.success'
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
case 'rejected':
|
|
20
|
+
return React.createElement(StatusText, {
|
|
21
|
+
role: "danger",
|
|
22
|
+
size: "small"
|
|
23
|
+
}, intl.formatMessage({
|
|
24
|
+
id: 'materialSurvey.submitStatus.failure'
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
default:
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { SurveySubmitStatusText as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { APIStatus } from '@elice/material-shared-types';
|
|
3
|
+
import type { GetOrgCourseGetResponses, GetOrgLectureGetResponses, GetOrgMaterialSurveyGetResponses } from '@elice/types';
|
|
4
|
+
export interface State {
|
|
5
|
+
vertical: boolean;
|
|
6
|
+
initStatus: APIStatus;
|
|
7
|
+
course?: GetOrgCourseGetResponses['course'];
|
|
8
|
+
lecture?: GetOrgLectureGetResponses['lecture'];
|
|
9
|
+
materialSurvey?: GetOrgMaterialSurveyGetResponses['materialSurvey'];
|
|
10
|
+
userId?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare type MaterialSurveyProps = {
|
|
13
|
+
materialSurveyId: number;
|
|
14
|
+
userId?: number;
|
|
15
|
+
locale?: string;
|
|
16
|
+
onSubmit?: (isSucceeded: boolean, isCorrect?: boolean) => void;
|
|
17
|
+
onNext?: () => void;
|
|
18
|
+
};
|
|
19
|
+
interface MaterialSurveyProviderProps extends Omit<MaterialSurveyProps, 'locale'> {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
interface DispatchContextType {
|
|
23
|
+
onSubmit: (isSucceeded: boolean, isCorrect?: boolean) => void;
|
|
24
|
+
refreshOrgMaterialSurvey: (signal?: AbortSignal | undefined) => Promise<void>;
|
|
25
|
+
setVertical: React.Dispatch<React.SetStateAction<boolean>>;
|
|
26
|
+
onNext?: () => void;
|
|
27
|
+
}
|
|
28
|
+
declare function MaterialSurveyProvider({ materialSurveyId, userId, onSubmit, onNext, children, }: MaterialSurveyProviderProps): JSX.Element;
|
|
29
|
+
declare function useMaterialSurveyState(): State;
|
|
30
|
+
declare function useMaterialSurveyDispatch(): DispatchContextType;
|
|
31
|
+
export { MaterialSurveyProvider, useMaterialSurveyState, useMaterialSurveyDispatch, };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { config, getOrgMaterialSurveyGet, getOrgCourseGet, getOrgLectureGet } from '@elice/api-client';
|
|
3
|
+
import { useMaterialConfigApiClientUpdate } from '@elice/material-shared-utils';
|
|
4
|
+
|
|
5
|
+
const StateContext = React.createContext(undefined);
|
|
6
|
+
const DispatchContext = React.createContext(undefined);
|
|
7
|
+
StateContext.displayName = 'MaterialSurveyStateContext';
|
|
8
|
+
DispatchContext.displayName = 'MaterialSurveyDispatchContext';
|
|
9
|
+
|
|
10
|
+
function MaterialSurveyProvider({
|
|
11
|
+
materialSurveyId,
|
|
12
|
+
userId,
|
|
13
|
+
onSubmit = () => void 0,
|
|
14
|
+
onNext,
|
|
15
|
+
children
|
|
16
|
+
}) {
|
|
17
|
+
const [course, setCourse] = React.useState();
|
|
18
|
+
const [lecture, setLecture] = React.useState();
|
|
19
|
+
const [materialSurvey, setMaterialSurvey] = React.useState();
|
|
20
|
+
const [initStatus, setInitStatus] = React.useState('idle');
|
|
21
|
+
const [vertical, setVertical] = React.useState(false);
|
|
22
|
+
const canInit = useMaterialConfigApiClientUpdate(config.init);
|
|
23
|
+
const doInitilize = React.useCallback(async () => {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const {
|
|
26
|
+
signal
|
|
27
|
+
} = controller;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
setInitStatus('pending'); // fetch materialSurvey
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
materialSurvey
|
|
34
|
+
} = await getOrgMaterialSurveyGet({
|
|
35
|
+
materialSurveyId
|
|
36
|
+
}, {
|
|
37
|
+
signal
|
|
38
|
+
}); // fetch course
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
course
|
|
42
|
+
} = await getOrgCourseGet({
|
|
43
|
+
courseId: materialSurvey.courseId
|
|
44
|
+
}, {
|
|
45
|
+
signal
|
|
46
|
+
}); // fetch lecture
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
lecture
|
|
50
|
+
} = await getOrgLectureGet({
|
|
51
|
+
lectureId: materialSurvey.lectureId
|
|
52
|
+
}, {
|
|
53
|
+
signal
|
|
54
|
+
});
|
|
55
|
+
setMaterialSurvey(materialSurvey);
|
|
56
|
+
setCourse(course);
|
|
57
|
+
setLecture(lecture);
|
|
58
|
+
setInitStatus('resolved');
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(error);
|
|
61
|
+
setInitStatus('rejected');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return () => controller.abort();
|
|
65
|
+
}, [materialSurveyId]);
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
if (canInit) {
|
|
68
|
+
void doInitilize();
|
|
69
|
+
}
|
|
70
|
+
}, [canInit, doInitilize]); //
|
|
71
|
+
//
|
|
72
|
+
// materialSurvey refresher
|
|
73
|
+
|
|
74
|
+
const refreshOrgMaterialSurvey = React.useCallback(signal => {
|
|
75
|
+
return getOrgMaterialSurveyGet({
|
|
76
|
+
materialSurveyId
|
|
77
|
+
}, {
|
|
78
|
+
signal
|
|
79
|
+
}).then(response => {
|
|
80
|
+
setMaterialSurvey(response.materialSurvey);
|
|
81
|
+
}).catch(error => {
|
|
82
|
+
console.error(error);
|
|
83
|
+
});
|
|
84
|
+
}, [materialSurveyId]);
|
|
85
|
+
return React.createElement(StateContext.Provider, {
|
|
86
|
+
value: {
|
|
87
|
+
course,
|
|
88
|
+
lecture,
|
|
89
|
+
materialSurvey,
|
|
90
|
+
userId,
|
|
91
|
+
vertical,
|
|
92
|
+
initStatus
|
|
93
|
+
}
|
|
94
|
+
}, React.createElement(DispatchContext.Provider, {
|
|
95
|
+
value: {
|
|
96
|
+
onSubmit,
|
|
97
|
+
onNext,
|
|
98
|
+
refreshOrgMaterialSurvey,
|
|
99
|
+
setVertical
|
|
100
|
+
}
|
|
101
|
+
}, children));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function useMaterialSurveyState() {
|
|
105
|
+
const context = React.useContext(StateContext);
|
|
106
|
+
|
|
107
|
+
if (context === undefined) {
|
|
108
|
+
throw new Error('useMaterialSurveyState must be used within a MaterialSurveyProvider');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return context;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function useMaterialSurveyDispatch() {
|
|
115
|
+
const context = React.useContext(DispatchContext);
|
|
116
|
+
|
|
117
|
+
if (context === undefined) {
|
|
118
|
+
throw new Error('useMaterialSurveyDispatch must be used within a MaterialSurveyProvider');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return context;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { MaterialSurveyProvider, useMaterialSurveyDispatch, useMaterialSurveyState };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { MarkdownEditorFileUploadReqFn } from '@elice/markdown';
|
|
3
|
+
import type { GetOrgMaterialSurveyGetResponses } from '@elice/types';
|
|
4
|
+
import type { FormState } from 'react-hook-form';
|
|
5
|
+
export declare type MaterialSurveyEditValue = Pick<GetOrgMaterialSurveyGetResponses['materialSurvey'], 'id' | 'questionInfoList'>;
|
|
6
|
+
export declare type MaterialSurveyEditFormState = Pick<FormState<Record<string, any>>, 'isDirty' | 'isValid'>;
|
|
7
|
+
export interface MaterialSurveyEditProps {
|
|
8
|
+
/** Value of material survey edit form. */
|
|
9
|
+
value: MaterialSurveyEditValue;
|
|
10
|
+
/**
|
|
11
|
+
* Is editing disabled?
|
|
12
|
+
* When true, cannot change `optionType`, `optionInfo` and `answerInfo`.
|
|
13
|
+
*/
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Locale of edit form. */
|
|
16
|
+
locale: string;
|
|
17
|
+
/** Handle form change event. */
|
|
18
|
+
onChange: (value: MaterialSurveyEditValue) => void;
|
|
19
|
+
/** Handle form state changes. (`FormState` from react-hook-form) */
|
|
20
|
+
onFormStateChange?: (state: MaterialSurveyEditFormState) => void;
|
|
21
|
+
/** Handle file upload. */
|
|
22
|
+
onFileUploadRequest: MarkdownEditorFileUploadReqFn;
|
|
23
|
+
}
|
|
24
|
+
declare const MaterialSurveyEdit: React.ForwardRefExoticComponent<MaterialSurveyEditProps & React.RefAttributes<HTMLFormElement>>;
|
|
25
|
+
export default MaterialSurveyEdit;
|