@elice/material-survey 1.240718.0-trasncript.2 → 1.240718.2
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/cjs/components/markdown-editor/index.d.ts +2 -1
- package/cjs/components/markdown-editor/index.js +10 -19
- package/cjs/components/material-survey/MaterialSurvey.js +57 -82
- package/cjs/components/material-survey/MaterialSurveyInfo.js +59 -69
- package/cjs/components/material-survey/MaterialSurveySelectMultiple.js +90 -131
- package/cjs/components/material-survey/MaterialSurveySelectOne.js +86 -125
- package/cjs/components/material-survey/MaterialSurveyShimmer.js +40 -47
- package/cjs/components/material-survey/MaterialSurveyText.js +75 -114
- package/cjs/components/material-survey/SurveyResultBadge.js +10 -17
- package/cjs/components/material-survey/SurveySubmitStatusText.js +16 -21
- package/cjs/components/material-survey/context/MaterialSurveyContext.d.ts +1 -1
- package/cjs/components/material-survey/context/MaterialSurveyContext.js +74 -115
- package/cjs/components/material-survey-edit/MaterialSurveyEdit.js +36 -49
- package/cjs/components/material-survey-edit/MaterialSurveyEditContent.js +91 -113
- package/cjs/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +87 -100
- package/cjs/components/material-survey-edit/context.js +2 -8
- package/cjs/components/material-survey-edit/utils/editValue.js +11 -17
- package/cjs/components/shared/StyledMarkdown.js +1 -5
- package/cjs/components/shared/SurveyContentBox.js +74 -85
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +7 -13
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -24
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +89 -66
- package/cjs/components/shared/question-radio/QuestionRadio.js +7 -13
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +17 -24
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +80 -59
- package/es/components/markdown-editor/index.d.ts +2 -1
- package/es/components/markdown-editor/index.js +10 -15
- package/es/components/material-survey/MaterialSurvey.js +57 -77
- package/es/components/material-survey/MaterialSurveyInfo.js +59 -65
- package/es/components/material-survey/MaterialSurveySelectMultiple.js +90 -127
- package/es/components/material-survey/MaterialSurveySelectOne.js +86 -121
- package/es/components/material-survey/MaterialSurveyShimmer.js +40 -43
- package/es/components/material-survey/MaterialSurveyText.js +75 -109
- package/es/components/material-survey/SurveyResultBadge.js +10 -13
- package/es/components/material-survey/SurveySubmitStatusText.js +16 -17
- package/es/components/material-survey/context/MaterialSurveyContext.d.ts +1 -1
- package/es/components/material-survey/context/MaterialSurveyContext.js +75 -112
- package/es/components/material-survey-edit/MaterialSurveyEdit.js +36 -45
- package/es/components/material-survey-edit/MaterialSurveyEditContent.js +90 -107
- package/es/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +87 -96
- package/es/components/material-survey-edit/context.js +2 -4
- package/es/components/material-survey-edit/utils/editValue.js +11 -17
- package/es/components/shared/StyledMarkdown.js +1 -1
- package/es/components/shared/SurveyContentBox.js +74 -81
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +7 -9
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -20
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +89 -61
- package/es/components/shared/question-radio/QuestionRadio.js +7 -9
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
- package/es/components/shared/question-radio/QuestionRadioContext.js +17 -20
- package/es/components/shared/question-radio/QuestionRadioOption.js +80 -54
- package/package.json +12 -9
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -399
- package/cjs/components/material-survey/index.js +0 -9
- package/cjs/components/material-survey/locales/index.js +0 -13
- package/cjs/components/material-survey-edit/index.js +0 -7
- package/cjs/components/material-survey-edit/locales/index.js +0 -13
- package/cjs/components/shared/index.js +0 -13
- package/es/_virtual/_rollupPluginBabelHelpers.js +0 -386
- package/es/components/material-survey/index.js +0 -2
- package/es/components/material-survey/locales/index.js +0 -4
- package/es/components/material-survey-edit/index.js +0 -1
- package/es/components/material-survey-edit/locales/index.js +0 -4
- package/es/components/shared/index.js +0 -4
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
7
5
|
var React = require('react');
|
|
8
6
|
var apiClient = require('@elice/api-client');
|
|
9
7
|
var designTokens = require('@elice/design-tokens');
|
|
@@ -15,66 +13,55 @@ var MaterialSurveyContext = require('./context/MaterialSurveyContext.js');
|
|
|
15
13
|
var SurveyResultBadge = require('./SurveyResultBadge.js');
|
|
16
14
|
var SurveySubmitStatusText = require('./SurveySubmitStatusText.js');
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
21
|
-
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
22
|
-
|
|
23
|
-
var StyledTextarea = styled__default.default.textarea.withConfig({
|
|
16
|
+
const StyledTextarea = styled.textarea.withConfig({
|
|
24
17
|
componentId: "sc-16tkulg-0"
|
|
25
|
-
})(["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:", ";}"], designTokens.base.color.navy2, designTokens.base.color.navy5, designTokens.base.color.navy2,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var MaterialSurveyText = function MaterialSurveyText() {
|
|
18
|
+
})(["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:", ";}"], designTokens.base.color.navy2, designTokens.base.color.navy5, designTokens.base.color.navy2, ({
|
|
19
|
+
disabled
|
|
20
|
+
}) => disabled ? 'not-allowed' : 'text');
|
|
21
|
+
const MaterialSurveyText = () => {
|
|
30
22
|
// context
|
|
31
|
-
|
|
32
|
-
lecture
|
|
33
|
-
materialSurvey
|
|
34
|
-
userId
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
const {
|
|
24
|
+
lecture,
|
|
25
|
+
materialSurvey,
|
|
26
|
+
userId
|
|
27
|
+
} = MaterialSurveyContext.useMaterialSurveyState();
|
|
28
|
+
const {
|
|
29
|
+
onSubmit,
|
|
30
|
+
onNext,
|
|
31
|
+
refreshOrgMaterialSurvey
|
|
32
|
+
} = MaterialSurveyContext.useMaterialSurveyDispatch();
|
|
39
33
|
// state
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
setMaterialSurveyResponse = _React$useState2[1];
|
|
45
|
-
var _React$useState3 = React__default.default.useState('idle'),
|
|
46
|
-
_React$useState4 = _rollupPluginBabelHelpers.slicedToArray(_React$useState3, 2),
|
|
47
|
-
submitStatus = _React$useState4[0],
|
|
48
|
-
setSubmitStatus = _React$useState4[1];
|
|
49
|
-
var _React$useState5 = React__default.default.useState(''),
|
|
50
|
-
_React$useState6 = _rollupPluginBabelHelpers.slicedToArray(_React$useState5, 2),
|
|
51
|
-
answer = _React$useState6[0],
|
|
52
|
-
setAnswer = _React$useState6[1];
|
|
34
|
+
const intl$1 = intl.useRawEliceIntl();
|
|
35
|
+
const [materialSurveyResponse, setMaterialSurveyResponse] = React.useState();
|
|
36
|
+
const [submitStatus, setSubmitStatus] = React.useState('idle');
|
|
37
|
+
const [answer, setAnswer] = React.useState('');
|
|
53
38
|
// survey response fetcher
|
|
54
|
-
|
|
39
|
+
React.useEffect(() => {
|
|
55
40
|
if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const {
|
|
43
|
+
signal
|
|
44
|
+
} = controller;
|
|
58
45
|
apiClient.getOrgMaterialSurveyResponseGet({
|
|
59
46
|
surveyResponseId: materialSurvey.lastSurveyResponseId
|
|
60
47
|
}, {
|
|
61
|
-
signal
|
|
62
|
-
}).then(
|
|
48
|
+
signal
|
|
49
|
+
}).then(response => {
|
|
63
50
|
setMaterialSurveyResponse(response.surveyResponse);
|
|
64
51
|
setAnswer(response.surveyResponse.answers[0]);
|
|
65
|
-
}).catch(
|
|
52
|
+
}).catch(error => {
|
|
66
53
|
console.error(error);
|
|
67
54
|
});
|
|
68
|
-
return
|
|
69
|
-
return controller.abort();
|
|
70
|
-
};
|
|
55
|
+
return () => controller.abort();
|
|
71
56
|
}
|
|
72
57
|
}, [materialSurvey, userId]);
|
|
73
58
|
// survey response fetcher
|
|
74
|
-
|
|
59
|
+
React.useEffect(() => {
|
|
75
60
|
if (userId && materialSurvey) {
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const {
|
|
63
|
+
signal
|
|
64
|
+
} = controller;
|
|
78
65
|
apiClient.getOrgMaterialSurveyResponseList({
|
|
79
66
|
materialSurveyId: materialSurvey.id,
|
|
80
67
|
filterUserIds: [userId],
|
|
@@ -83,72 +70,47 @@ var MaterialSurveyText = function MaterialSurveyText() {
|
|
|
83
70
|
offset: 0,
|
|
84
71
|
count: 1
|
|
85
72
|
}, {
|
|
86
|
-
signal
|
|
87
|
-
}).then(
|
|
88
|
-
|
|
73
|
+
signal
|
|
74
|
+
}).then(response => {
|
|
75
|
+
const surveyResponse = response.surveyResponses[0];
|
|
89
76
|
setMaterialSurveyResponse(surveyResponse);
|
|
90
77
|
setAnswer(typeof (surveyResponse === null || surveyResponse === void 0 ? void 0 : surveyResponse.answers[0]) === 'string' ? surveyResponse.answers[0] : '');
|
|
91
|
-
}).catch(
|
|
78
|
+
}).catch(error => {
|
|
92
79
|
console.error(error);
|
|
93
80
|
});
|
|
94
|
-
return
|
|
95
|
-
return controller.abort();
|
|
96
|
-
};
|
|
81
|
+
return () => controller.abort();
|
|
97
82
|
}
|
|
98
83
|
}, [materialSurvey, userId]);
|
|
99
84
|
// submit handler
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
setMaterialSurveyResponse(surveyResponse);
|
|
130
|
-
void refreshOrgMaterialSurvey();
|
|
131
|
-
onSubmit(true);
|
|
132
|
-
setSubmitStatus('resolved');
|
|
133
|
-
_context.next = 23;
|
|
134
|
-
break;
|
|
135
|
-
case 18:
|
|
136
|
-
_context.prev = 18;
|
|
137
|
-
_context.t0 = _context["catch"](3);
|
|
138
|
-
console.error(_context.t0);
|
|
139
|
-
onSubmit(false);
|
|
140
|
-
setSubmitStatus('rejected');
|
|
141
|
-
case 23:
|
|
142
|
-
case "end":
|
|
143
|
-
return _context.stop();
|
|
144
|
-
}
|
|
145
|
-
}, _callee, null, [[3, 18]]);
|
|
146
|
-
}));
|
|
147
|
-
return function handleSubmit() {
|
|
148
|
-
return _ref2.apply(this, arguments);
|
|
149
|
-
};
|
|
150
|
-
}();
|
|
151
|
-
var commonProps = {
|
|
85
|
+
const handleSubmit = async () => {
|
|
86
|
+
if (!materialSurvey) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
setSubmitStatus('pending');
|
|
90
|
+
try {
|
|
91
|
+
const {
|
|
92
|
+
surveyResponseId
|
|
93
|
+
} = await apiClient.postOrgMaterialSurveyResponseAdd({
|
|
94
|
+
materialSurveyId: materialSurvey.id,
|
|
95
|
+
answers: [answer] // FIXME: Type mismatch
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const {
|
|
99
|
+
surveyResponse
|
|
100
|
+
} = await apiClient.getOrgMaterialSurveyResponseGet({
|
|
101
|
+
surveyResponseId
|
|
102
|
+
});
|
|
103
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
104
|
+
void refreshOrgMaterialSurvey();
|
|
105
|
+
onSubmit(true);
|
|
106
|
+
setSubmitStatus('resolved');
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(error);
|
|
109
|
+
onSubmit(false);
|
|
110
|
+
setSubmitStatus('rejected');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const commonProps = {
|
|
152
114
|
type: 'text',
|
|
153
115
|
autoFocus: answer.length === 0,
|
|
154
116
|
disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId,
|
|
@@ -156,19 +118,19 @@ var MaterialSurveyText = function MaterialSurveyText() {
|
|
|
156
118
|
id: 'materialSurvey.text.placeholder'
|
|
157
119
|
}),
|
|
158
120
|
value: answer,
|
|
159
|
-
onChange:
|
|
121
|
+
onChange: e => {
|
|
160
122
|
setAnswer(e.target.value);
|
|
161
123
|
}
|
|
162
124
|
};
|
|
163
|
-
return
|
|
125
|
+
return React.createElement(SurveyContentBox.default, {
|
|
164
126
|
title: intl$1.formatMessage({
|
|
165
127
|
id: 'materialSurvey.myAnswer'
|
|
166
128
|
}),
|
|
167
129
|
onNext: onNext,
|
|
168
|
-
submitResult:
|
|
130
|
+
submitResult: React.createElement(SurveyResultBadge.default, {
|
|
169
131
|
materialSurveyResponse: materialSurveyResponse
|
|
170
132
|
}),
|
|
171
|
-
submitStatus:
|
|
133
|
+
submitStatus: React.createElement(SurveySubmitStatusText.default, {
|
|
172
134
|
status: submitStatus
|
|
173
135
|
}),
|
|
174
136
|
footerActions: [{
|
|
@@ -182,11 +144,10 @@ var MaterialSurveyText = function MaterialSurveyText() {
|
|
|
182
144
|
transparent: false,
|
|
183
145
|
role: 'primary',
|
|
184
146
|
onClick: handleSubmit
|
|
185
|
-
}]
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
147
|
+
}]
|
|
148
|
+
}, React.createElement(StyledTextarea, Object.assign({
|
|
149
|
+
id: "survey-text-answer"
|
|
150
|
+
}, commonProps)));
|
|
190
151
|
};
|
|
191
152
|
|
|
192
153
|
exports.default = MaterialSurveyText;
|
|
@@ -2,31 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
6
5
|
var React = require('react');
|
|
7
6
|
var blocks = require('@elice/blocks');
|
|
8
7
|
var intl = require('@elice/intl');
|
|
9
8
|
var index = require('../../helpers/index.js');
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var materialSurveyResponse = _ref.materialSurveyResponse;
|
|
17
|
-
var intl$1 = intl.useRawEliceIntl();
|
|
18
|
-
var status = React__default.default.useMemo(function () {
|
|
19
|
-
return index.getSurveyResultStatus(materialSurveyResponse);
|
|
20
|
-
}, [materialSurveyResponse]);
|
|
10
|
+
const SurveyResultBadge = ({
|
|
11
|
+
materialSurveyResponse
|
|
12
|
+
}) => {
|
|
13
|
+
const intl$1 = intl.useRawEliceIntl();
|
|
14
|
+
const status = React.useMemo(() => index.getSurveyResultStatus(materialSurveyResponse), [materialSurveyResponse]);
|
|
21
15
|
switch (status) {
|
|
22
16
|
case index.SurveyResultStatus.Submitted:
|
|
23
|
-
return
|
|
17
|
+
return React.createElement(blocks.BadgeNext, {
|
|
24
18
|
type: "quiet",
|
|
25
|
-
role: "primary"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
19
|
+
role: "primary"
|
|
20
|
+
}, intl$1.formatMessage({
|
|
21
|
+
id: 'materialSurvey.resultStatus.submitted'
|
|
22
|
+
}));
|
|
30
23
|
default:
|
|
31
24
|
return null;
|
|
32
25
|
}
|
|
@@ -2,39 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
var blocks = require('@elice/blocks');
|
|
7
7
|
var intl = require('@elice/intl');
|
|
8
8
|
var muiSystem = require('@elice/mui-system');
|
|
9
9
|
var styled = require('styled-components');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
14
|
-
|
|
15
|
-
var StyledSuccessStatusText = styled__default.default(blocks.StatusText).withConfig({
|
|
11
|
+
const StyledSuccessStatusText = styled(blocks.StatusText).withConfig({
|
|
16
12
|
componentId: "sc-szxa5m-0"
|
|
17
13
|
})(["color:", ";"], muiSystem.colors.green[400]);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const SurveySubmitStatusText = ({
|
|
15
|
+
status
|
|
16
|
+
}) => {
|
|
17
|
+
const intl$1 = intl.useRawEliceIntl();
|
|
21
18
|
switch (status) {
|
|
22
19
|
case 'resolved':
|
|
23
|
-
return
|
|
20
|
+
return React.createElement(StyledSuccessStatusText, {
|
|
24
21
|
role: "success",
|
|
25
|
-
size: "small"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
22
|
+
size: "small"
|
|
23
|
+
}, intl$1.formatMessage({
|
|
24
|
+
id: 'materialSurvey.submitStatus.success'
|
|
25
|
+
}));
|
|
30
26
|
case 'rejected':
|
|
31
|
-
return
|
|
27
|
+
return React.createElement(blocks.StatusText, {
|
|
32
28
|
role: "danger",
|
|
33
|
-
size: "small"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
29
|
+
size: "small"
|
|
30
|
+
}, intl$1.formatMessage({
|
|
31
|
+
id: 'materialSurvey.submitStatus.failure'
|
|
32
|
+
}));
|
|
38
33
|
default:
|
|
39
34
|
return null;
|
|
40
35
|
}
|
|
@@ -25,7 +25,7 @@ interface DispatchContextType {
|
|
|
25
25
|
setVertical: React.Dispatch<React.SetStateAction<boolean>>;
|
|
26
26
|
onNext?: () => void;
|
|
27
27
|
}
|
|
28
|
-
declare function MaterialSurveyProvider({ materialSurveyId, userId, onSubmit, onNext, children, }: MaterialSurveyProviderProps): JSX.Element;
|
|
28
|
+
declare function MaterialSurveyProvider({ materialSurveyId, userId, onSubmit, onNext, children, }: MaterialSurveyProviderProps): React.JSX.Element;
|
|
29
29
|
declare function useMaterialSurveyState(): State;
|
|
30
30
|
declare function useMaterialSurveyDispatch(): DispatchContextType;
|
|
31
31
|
export { MaterialSurveyProvider, useMaterialSurveyState, useMaterialSurveyDispatch, };
|
|
@@ -1,143 +1,102 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
4
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
5
3
|
var React = require('react');
|
|
6
4
|
var apiClient = require('@elice/api-client');
|
|
7
5
|
var materialSharedUtils = require('@elice/material-shared-utils');
|
|
8
6
|
var types = require('@elice/types');
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
13
|
-
|
|
14
|
-
var StateContext = React__default.default.createContext(undefined);
|
|
15
|
-
var DispatchContext = React__default.default.createContext(undefined);
|
|
8
|
+
const StateContext = React.createContext(undefined);
|
|
9
|
+
const DispatchContext = React.createContext(undefined);
|
|
16
10
|
StateContext.displayName = 'MaterialSurveyStateContext';
|
|
17
11
|
DispatchContext.displayName = 'MaterialSurveyDispatchContext';
|
|
18
|
-
function MaterialSurveyProvider(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
12
|
+
function MaterialSurveyProvider({
|
|
13
|
+
materialSurveyId,
|
|
14
|
+
userId,
|
|
15
|
+
onSubmit = () => void 0,
|
|
16
|
+
onNext,
|
|
17
|
+
children
|
|
18
|
+
}) {
|
|
19
|
+
const [course, setCourse] = React.useState();
|
|
20
|
+
const [lecture, setLecture] = React.useState();
|
|
21
|
+
const [initStatus, setInitStatus] = React.useState('idle');
|
|
22
|
+
const [vertical, setVertical] = React.useState(false);
|
|
23
|
+
const canInit = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
|
|
24
|
+
const {
|
|
25
|
+
materialSurvey,
|
|
26
|
+
materialLecturePage,
|
|
27
|
+
refetch: refreshOrgMaterialSurvey
|
|
28
|
+
} = materialSharedUtils.useMaterialFetchRaw(types.enums.LectureMaterialType.Survey, React.useCallback(signal => apiClient.getOrgMaterialSurveyGet({
|
|
29
|
+
materialSurveyId
|
|
30
|
+
}, {
|
|
31
|
+
signal
|
|
32
|
+
}), [materialSurveyId]), canInit);
|
|
33
|
+
const doInitilize = React.useCallback(async () => {
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const {
|
|
36
|
+
signal
|
|
37
|
+
} = controller;
|
|
38
|
+
try {
|
|
39
|
+
setInitStatus('pending');
|
|
40
|
+
if (!materialLecturePage) {
|
|
41
|
+
throw new Error('materialSurvey is not ready');
|
|
42
|
+
}
|
|
43
|
+
// fetch course
|
|
44
|
+
const {
|
|
45
|
+
course
|
|
46
|
+
} = await apiClient.getOrgCourseGet({
|
|
47
|
+
courseId: materialLecturePage.courseId
|
|
47
48
|
}, {
|
|
48
|
-
signal
|
|
49
|
+
signal
|
|
49
50
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
case 6:
|
|
69
|
-
_context.next = 8;
|
|
70
|
-
return apiClient.getOrgCourseGet({
|
|
71
|
-
courseId: materialLecturePage.courseId
|
|
72
|
-
}, {
|
|
73
|
-
signal: signal
|
|
74
|
-
});
|
|
75
|
-
case 8:
|
|
76
|
-
_yield$getOrgCourseGe = _context.sent;
|
|
77
|
-
_course = _yield$getOrgCourseGe.course;
|
|
78
|
-
_context.next = 12;
|
|
79
|
-
return apiClient.getOrgLectureGet({
|
|
80
|
-
lectureId: materialLecturePage.lectureId
|
|
81
|
-
}, {
|
|
82
|
-
signal: signal
|
|
83
|
-
});
|
|
84
|
-
case 12:
|
|
85
|
-
_yield$getOrgLectureG = _context.sent;
|
|
86
|
-
_lecture = _yield$getOrgLectureG.lecture;
|
|
87
|
-
setCourse(_course);
|
|
88
|
-
setLecture(_lecture);
|
|
89
|
-
setInitStatus('resolved');
|
|
90
|
-
_context.next = 23;
|
|
91
|
-
break;
|
|
92
|
-
case 19:
|
|
93
|
-
_context.prev = 19;
|
|
94
|
-
_context.t0 = _context["catch"](2);
|
|
95
|
-
console.error(_context.t0);
|
|
96
|
-
setInitStatus('rejected');
|
|
97
|
-
case 23:
|
|
98
|
-
return _context.abrupt("return", function () {
|
|
99
|
-
return controller.abort();
|
|
100
|
-
});
|
|
101
|
-
case 24:
|
|
102
|
-
case "end":
|
|
103
|
-
return _context.stop();
|
|
104
|
-
}
|
|
105
|
-
}, _callee, null, [[2, 19]]);
|
|
106
|
-
})), [materialLecturePage]);
|
|
107
|
-
React__default.default.useEffect(function () {
|
|
51
|
+
// fetch lecture
|
|
52
|
+
const {
|
|
53
|
+
lecture
|
|
54
|
+
} = await apiClient.getOrgLectureGet({
|
|
55
|
+
lectureId: materialLecturePage.lectureId
|
|
56
|
+
}, {
|
|
57
|
+
signal
|
|
58
|
+
});
|
|
59
|
+
setCourse(course);
|
|
60
|
+
setLecture(lecture);
|
|
61
|
+
setInitStatus('resolved');
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
setInitStatus('rejected');
|
|
65
|
+
}
|
|
66
|
+
return () => controller.abort();
|
|
67
|
+
}, [materialLecturePage]);
|
|
68
|
+
React.useEffect(() => {
|
|
108
69
|
if (canInit && materialLecturePage) {
|
|
109
70
|
void doInitilize();
|
|
110
71
|
}
|
|
111
72
|
}, [canInit, materialLecturePage, doInitilize]);
|
|
112
|
-
return
|
|
73
|
+
return React.createElement(StateContext.Provider, {
|
|
113
74
|
value: {
|
|
114
|
-
course
|
|
115
|
-
lecture
|
|
75
|
+
course,
|
|
76
|
+
lecture,
|
|
116
77
|
materialSurvey: materialSurvey !== null && materialSurvey !== void 0 ? materialSurvey : undefined,
|
|
117
|
-
userId
|
|
118
|
-
vertical
|
|
119
|
-
initStatus
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
});
|
|
78
|
+
userId,
|
|
79
|
+
vertical,
|
|
80
|
+
initStatus
|
|
81
|
+
}
|
|
82
|
+
}, React.createElement(DispatchContext.Provider, {
|
|
83
|
+
value: {
|
|
84
|
+
onSubmit,
|
|
85
|
+
onNext,
|
|
86
|
+
refreshOrgMaterialSurvey,
|
|
87
|
+
setVertical
|
|
88
|
+
}
|
|
89
|
+
}, children));
|
|
131
90
|
}
|
|
132
91
|
function useMaterialSurveyState() {
|
|
133
|
-
|
|
92
|
+
const context = React.useContext(StateContext);
|
|
134
93
|
if (context === undefined) {
|
|
135
94
|
throw new Error('useMaterialSurveyState must be used within a MaterialSurveyProvider');
|
|
136
95
|
}
|
|
137
96
|
return context;
|
|
138
97
|
}
|
|
139
98
|
function useMaterialSurveyDispatch() {
|
|
140
|
-
|
|
99
|
+
const context = React.useContext(DispatchContext);
|
|
141
100
|
if (context === undefined) {
|
|
142
101
|
throw new Error('useMaterialSurveyDispatch must be used within a MaterialSurveyProvider');
|
|
143
102
|
}
|