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