@elice/material-survey 1.230328.0 → 1.230418.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.
Files changed (54) hide show
  1. package/cjs/_virtual/_rollupPluginBabelHelpers.js +409 -0
  2. package/cjs/components/material-survey/MaterialSurvey.i18n.js +2 -2
  3. package/cjs/components/material-survey/MaterialSurvey.js +56 -51
  4. package/cjs/components/material-survey/MaterialSurveyInfo.js +6 -5
  5. package/cjs/components/material-survey/MaterialSurveySelectMultiple.js +117 -91
  6. package/cjs/components/material-survey/MaterialSurveySelectOne.js +110 -81
  7. package/cjs/components/material-survey/MaterialSurveyShimmer.js +13 -12
  8. package/cjs/components/material-survey/MaterialSurveyText.js +111 -80
  9. package/cjs/components/material-survey/SurveyResultBadge.js +9 -8
  10. package/cjs/components/material-survey/SurveySubmitStatusText.js +6 -8
  11. package/cjs/components/material-survey/context/MaterialSurveyContext.js +102 -79
  12. package/cjs/components/material-survey-edit/MaterialSurveyEdit.js +45 -38
  13. package/cjs/components/material-survey-edit/MaterialSurveyEditContent.js +79 -83
  14. package/cjs/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +71 -76
  15. package/cjs/components/material-survey-edit/context.js +4 -2
  16. package/cjs/components/material-survey-edit/locales.js +2 -2
  17. package/cjs/components/material-survey-edit/utils/editValue.js +17 -16
  18. package/cjs/components/shared/StyledMarkdown.js +4 -2
  19. package/cjs/components/shared/SurveyContentBox.js +48 -54
  20. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +7 -9
  21. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +15 -18
  22. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +48 -103
  23. package/cjs/components/shared/question-radio/QuestionRadio.js +7 -9
  24. package/cjs/components/shared/question-radio/QuestionRadioContext.js +15 -18
  25. package/cjs/components/shared/question-radio/QuestionRadioOption.js +41 -87
  26. package/cjs/helpers/index.js +0 -3
  27. package/cjs/index.js +7 -7
  28. package/es/_virtual/_rollupPluginBabelHelpers.js +394 -0
  29. package/es/components/material-survey/MaterialSurvey.i18n.js +2 -2
  30. package/es/components/material-survey/MaterialSurvey.js +51 -46
  31. package/es/components/material-survey/MaterialSurveyInfo.js +3 -4
  32. package/es/components/material-survey/MaterialSurveySelectMultiple.js +109 -85
  33. package/es/components/material-survey/MaterialSurveySelectOne.js +102 -75
  34. package/es/components/material-survey/MaterialSurveyShimmer.js +10 -11
  35. package/es/components/material-survey/MaterialSurveyText.js +106 -77
  36. package/es/components/material-survey/SurveyResultBadge.js +6 -7
  37. package/es/components/material-survey/SurveySubmitStatusText.js +3 -7
  38. package/es/components/material-survey/context/MaterialSurveyContext.js +103 -80
  39. package/es/components/material-survey-edit/MaterialSurveyEdit.js +41 -36
  40. package/es/components/material-survey-edit/MaterialSurveyEditContent.js +75 -81
  41. package/es/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +68 -75
  42. package/es/components/material-survey-edit/context.js +4 -2
  43. package/es/components/material-survey-edit/locales.js +2 -2
  44. package/es/components/material-survey-edit/utils/editValue.js +17 -16
  45. package/es/components/shared/StyledMarkdown.js +1 -1
  46. package/es/components/shared/SurveyContentBox.js +48 -54
  47. package/es/components/shared/question-checkbox/QuestionCheckbox.js +4 -8
  48. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +15 -18
  49. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +45 -102
  50. package/es/components/shared/question-radio/QuestionRadio.js +4 -8
  51. package/es/components/shared/question-radio/QuestionRadioContext.js +15 -18
  52. package/es/components/shared/question-radio/QuestionRadioOption.js +38 -86
  53. package/es/helpers/index.js +0 -3
  54. package/package.json +8 -8
@@ -1,3 +1,4 @@
1
+ import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
1
2
  import React from 'react';
2
3
  import { IntlProvider } from 'react-intl';
3
4
  import { useMeasure } from 'react-use';
@@ -10,67 +11,72 @@ import MaterialSurveyInfo from './MaterialSurveyInfo.js';
10
11
  import * as MaterialSurvey_i18n from './MaterialSurvey.i18n.js';
11
12
  import { en } from './MaterialSurvey.i18n.js';
12
13
 
13
- const AsyncMaterialSurveySelectMultiple = React.lazy(() => import('./MaterialSurveySelectMultiple.js'));
14
- const AsyncMaterialSurveyText = React.lazy(() => import('./MaterialSurveyText.js'));
15
- const AsyncMaterialSurveySelectOne = React.lazy(() => import('./MaterialSurveySelectOne.js'));
16
- const StyledMaterialSurveyInfo = styled.div.withConfig({
14
+ var AsyncMaterialSurveySelectMultiple = React.lazy(function () {
15
+ return import('./MaterialSurveySelectMultiple.js');
16
+ });
17
+ var AsyncMaterialSurveyText = React.lazy(function () {
18
+ return import('./MaterialSurveyText.js');
19
+ });
20
+ var AsyncMaterialSurveySelectOne = React.lazy(function () {
21
+ return import('./MaterialSurveySelectOne.js');
22
+ });
23
+ var StyledMaterialSurveyInfo = styled.div.withConfig({
17
24
  componentId: "sc-1fyzkvm-0"
18
25
  })([""]);
19
- const StyledMaterialSurveyContent = styled.div.withConfig({
26
+ var StyledMaterialSurveyContent = styled.div.withConfig({
20
27
  componentId: "sc-1fyzkvm-1"
21
28
  })([""]);
22
- const StyledMaterialSurveyWrapper = styled.div.withConfig({
29
+ var StyledMaterialSurveyWrapper = styled.div.withConfig({
23
30
  componentId: "sc-1fyzkvm-2"
24
- })(["display:flex;height:100%;flex-direction:", ";& > *{flex:", ";}& > *:first-child{margin-right:", ";margin-bottom:", ";}", "{height:", ";overflow-y:", ";}"], ({
25
- vertical
26
- }) => vertical ? 'column' : 'row', ({
27
- vertical
28
- }) => vertical ? 'auto' : '1 0 calc(50% - 1rem);', ({
29
- vertical
30
- }) => vertical ? '0' : '1rem', ({
31
- vertical
32
- }) => vertical ? '1rem' : '0', StyledMaterialSurveyInfo, ({
33
- vertical
34
- }) => vertical ? 'auto' : '100%', ({
35
- vertical
36
- }) => vertical ? 'intial' : 'auto');
37
-
38
- const MaterialSurvey = () => {
39
- const {
40
- materialSurvey,
41
- vertical
42
- } = useMaterialSurveyState();
43
- const {
44
- setVertical
45
- } = useMaterialSurveyDispatch();
46
- const [ref, {
47
- width
48
- }] = useMeasure();
49
- React.useEffect(() => {
31
+ })(["display:flex;height:100%;flex-direction:", ";& > *{flex:", ";}& > *:first-child{margin-right:", ";margin-bottom:", ";}", "{height:", ";overflow-y:", ";}"], function (_ref) {
32
+ var vertical = _ref.vertical;
33
+ return vertical ? 'column' : 'row';
34
+ }, function (_ref2) {
35
+ var vertical = _ref2.vertical;
36
+ return vertical ? 'auto' : '1 0 calc(50% - 1rem);';
37
+ }, function (_ref3) {
38
+ var vertical = _ref3.vertical;
39
+ return vertical ? '0' : '1rem';
40
+ }, function (_ref4) {
41
+ var vertical = _ref4.vertical;
42
+ return vertical ? '1rem' : '0';
43
+ }, StyledMaterialSurveyInfo, function (_ref5) {
44
+ var vertical = _ref5.vertical;
45
+ return vertical ? 'auto' : '100%';
46
+ }, function (_ref6) {
47
+ var vertical = _ref6.vertical;
48
+ return vertical ? 'intial' : 'auto';
49
+ });
50
+ var MaterialSurvey = function MaterialSurvey() {
51
+ var _useMaterialSurveySta = useMaterialSurveyState(),
52
+ materialSurvey = _useMaterialSurveySta.materialSurvey,
53
+ vertical = _useMaterialSurveySta.vertical;
54
+ var _useMaterialSurveyDis = useMaterialSurveyDispatch(),
55
+ setVertical = _useMaterialSurveyDis.setVertical;
56
+ var _useMeasure = useMeasure(),
57
+ _useMeasure2 = _slicedToArray(_useMeasure, 2),
58
+ ref = _useMeasure2[0],
59
+ width = _useMeasure2[1].width;
60
+ React.useEffect(function () {
50
61
  if (width > 0) {
51
62
  setVertical(width <= base.screen.medium);
52
63
  }
53
64
  }, [width, setVertical]);
54
- let Component = null;
55
-
65
+ var Component = null;
56
66
  switch (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.questionInfoList[0].optionType) {
57
67
  case enums.SurveyOptionType.SelectOne:
58
68
  Component = React.createElement(AsyncMaterialSurveySelectOne, null);
59
69
  break;
60
-
61
70
  case enums.SurveyOptionType.SelectMultiple:
62
71
  Component = React.createElement(AsyncMaterialSurveySelectMultiple, null);
63
72
  break;
64
-
65
73
  case enums.SurveyOptionType.Text:
66
74
  Component = React.createElement(AsyncMaterialSurveyText, null);
67
75
  break;
68
-
69
76
  default:
70
77
  Component = React.createElement(MaterialSurveyShimmer, null);
71
78
  break;
72
79
  }
73
-
74
80
  return React.createElement(React.Suspense, {
75
81
  fallback: null
76
82
  }, React.createElement(StyledMaterialSurveyWrapper, {
@@ -78,14 +84,13 @@ const MaterialSurvey = () => {
78
84
  vertical: vertical
79
85
  }, React.createElement(StyledMaterialSurveyInfo, null, React.createElement(MaterialSurveyInfo, null)), React.createElement(StyledMaterialSurveyContent, null, Component)));
80
86
  };
81
-
82
- const MaterialSurveyContainer = ({
83
- materialSurveyId,
84
- userId,
85
- locale = 'en',
86
- onSubmit,
87
- onNext
88
- }) => {
87
+ var MaterialSurveyContainer = function MaterialSurveyContainer(_ref7) {
88
+ var materialSurveyId = _ref7.materialSurveyId,
89
+ userId = _ref7.userId,
90
+ _ref7$locale = _ref7.locale,
91
+ locale = _ref7$locale === void 0 ? 'en' : _ref7$locale,
92
+ onSubmit = _ref7.onSubmit,
93
+ onNext = _ref7.onNext;
89
94
  return React.createElement(IntlProvider, {
90
95
  locale: locale,
91
96
  defaultLocale: "en",
@@ -5,10 +5,9 @@ import { MarkdownSSR } from '@elice/markdown';
5
5
  import SurveyContentBox from '../shared/SurveyContentBox.js';
6
6
  import { useMaterialSurveyState } from './context/MaterialSurveyContext.js';
7
7
 
8
- const MaterialSurveyInfo = () => {
9
- const {
10
- materialSurvey
11
- } = useMaterialSurveyState();
8
+ var MaterialSurveyInfo = function MaterialSurveyInfo() {
9
+ var _useMaterialSurveySta = useMaterialSurveyState(),
10
+ materialSurvey = _useMaterialSurveySta.materialSurvey;
12
11
  return React.createElement(SurveyContentBox, {
13
12
  title: materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.title
14
13
  }, materialSurvey ? React.createElement(Flex, null, React.createElement(Text, {
@@ -1,3 +1,4 @@
1
+ import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.js';
1
2
  import React from 'react';
2
3
  import { useIntl } from 'react-intl';
3
4
  import { getOrgMaterialSurveyResponseGet, getOrgMaterialSurveyResponseList, postOrgMaterialSurveyResponseAdd } from '@elice/api-client';
@@ -12,53 +13,57 @@ import { useMaterialSurveyState, useMaterialSurveyDispatch } from './context/Mat
12
13
  import SurveyResultBadge from './SurveyResultBadge.js';
13
14
  import SurveySubmitStatusText from './SurveySubmitStatusText.js';
14
15
 
15
- const MaterialSurveySelectMultiple = () => {
16
- var _a; // context
17
-
18
-
19
- const {
20
- course,
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 [selectedAnswer, setSelectedAnswer] = React.useState([]);
33
- const [materialSurveyResponse, setMaterialSurveyResponse] = React.useState();
34
- const [submitStatus, setSubmitStatus] = React.useState('idle'); // survey response fetcher
35
-
36
- React.useEffect(() => {
16
+ var MaterialSurveySelectMultiple = function MaterialSurveySelectMultiple() {
17
+ var _a;
18
+ // context
19
+ var _useMaterialSurveySta = useMaterialSurveyState(),
20
+ course = _useMaterialSurveySta.course,
21
+ lecture = _useMaterialSurveySta.lecture,
22
+ materialSurvey = _useMaterialSurveySta.materialSurvey,
23
+ userId = _useMaterialSurveySta.userId;
24
+ var _useMaterialSurveyDis = useMaterialSurveyDispatch(),
25
+ onSubmit = _useMaterialSurveyDis.onSubmit,
26
+ onNext = _useMaterialSurveyDis.onNext,
27
+ refreshOrgMaterialSurvey = _useMaterialSurveyDis.refreshOrgMaterialSurvey;
28
+ // state
29
+ var intl = useIntl();
30
+ var _React$useState = React.useState([]),
31
+ _React$useState2 = _slicedToArray(_React$useState, 2),
32
+ selectedAnswer = _React$useState2[0],
33
+ setSelectedAnswer = _React$useState2[1];
34
+ var _React$useState3 = React.useState(),
35
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
36
+ materialSurveyResponse = _React$useState4[0],
37
+ setMaterialSurveyResponse = _React$useState4[1];
38
+ var _React$useState5 = React.useState('idle'),
39
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
40
+ submitStatus = _React$useState6[0],
41
+ setSubmitStatus = _React$useState6[1];
42
+ // survey response fetcher
43
+ React.useEffect(function () {
37
44
  if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
38
- const controller = new AbortController();
39
- const {
40
- signal
41
- } = controller;
45
+ var controller = new AbortController();
46
+ var signal = controller.signal;
42
47
  getOrgMaterialSurveyResponseGet({
43
48
  surveyResponseId: materialSurvey.lastSurveyResponseId
44
49
  }, {
45
- signal
46
- }).then(response => {
50
+ signal: signal
51
+ }).then(function (response) {
47
52
  setMaterialSurveyResponse(response.surveyResponse);
48
53
  setSelectedAnswer(response.surveyResponse.answers[0]);
49
- }).catch(error => {
54
+ }).catch(function (error) {
50
55
  console.error(error);
51
56
  });
52
- return () => controller.abort();
57
+ return function () {
58
+ return controller.abort();
59
+ };
53
60
  }
54
- }, [materialSurvey, userId]); // survey response fetcher
55
-
56
- React.useEffect(() => {
61
+ }, [materialSurvey, userId]);
62
+ // survey response fetcher
63
+ React.useEffect(function () {
57
64
  if (userId && materialSurvey) {
58
- const controller = new AbortController();
59
- const {
60
- signal
61
- } = controller;
65
+ var controller = new AbortController();
66
+ var signal = controller.signal;
62
67
  getOrgMaterialSurveyResponseList({
63
68
  materialSurveyId: materialSurvey.id,
64
69
  filterUserIds: [userId],
@@ -67,65 +72,83 @@ const MaterialSurveySelectMultiple = () => {
67
72
  offset: 0,
68
73
  count: 1
69
74
  }, {
70
- signal
71
- }).then(response => {
72
- const surveyResponse = response.surveyResponses[0];
73
-
74
- const getAnswer = () => {
75
+ signal: signal
76
+ }).then(function (response) {
77
+ var surveyResponse = response.surveyResponses[0];
78
+ var getAnswer = function getAnswer() {
75
79
  if (!surveyResponse) {
76
80
  return [];
77
81
  }
78
-
79
82
  if (!Array.isArray(surveyResponse.answers)) {
80
83
  return [];
81
84
  }
82
-
83
85
  if (typeof surveyResponse.answers[0] === 'string') {
84
86
  return [];
85
87
  }
86
-
87
88
  return surveyResponse.answers[0];
88
89
  };
89
-
90
90
  setMaterialSurveyResponse(surveyResponse);
91
91
  setSelectedAnswer(getAnswer());
92
- }).catch(error => {
92
+ }).catch(function (error) {
93
93
  console.error(error);
94
94
  });
95
- return () => controller.abort();
95
+ return function () {
96
+ return controller.abort();
97
+ };
96
98
  }
97
- }, [materialSurvey, userId]); // submit handler
98
-
99
- const handleSubmit = async () => {
100
- if (!materialSurvey) {
101
- return;
102
- }
103
-
104
- setSubmitStatus('pending');
105
-
106
- try {
107
- const {
108
- surveyResponseId
109
- } = await postOrgMaterialSurveyResponseAdd({
110
- materialSurveyId: materialSurvey.id,
111
- answers: [selectedAnswer]
112
- });
113
- const {
114
- surveyResponse
115
- } = await getOrgMaterialSurveyResponseGet({
116
- surveyResponseId
117
- });
118
- setMaterialSurveyResponse(surveyResponse);
119
- void refreshOrgMaterialSurvey();
120
- onSubmit(true);
121
- setSubmitStatus('resolved');
122
- } catch (error) {
123
- console.error(error);
124
- onSubmit(false);
125
- setSubmitStatus('rejected');
126
- }
127
- };
128
-
99
+ }, [materialSurvey, userId]);
100
+ // submit handler
101
+ var handleSubmit = /*#__PURE__*/function () {
102
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
103
+ var _yield$postOrgMateria, surveyResponseId, _yield$getOrgMaterial, surveyResponse;
104
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
105
+ while (1) switch (_context.prev = _context.next) {
106
+ case 0:
107
+ if (materialSurvey) {
108
+ _context.next = 2;
109
+ break;
110
+ }
111
+ return _context.abrupt("return");
112
+ case 2:
113
+ setSubmitStatus('pending');
114
+ _context.prev = 3;
115
+ _context.next = 6;
116
+ return postOrgMaterialSurveyResponseAdd({
117
+ materialSurveyId: materialSurvey.id,
118
+ answers: [selectedAnswer]
119
+ });
120
+ case 6:
121
+ _yield$postOrgMateria = _context.sent;
122
+ surveyResponseId = _yield$postOrgMateria.surveyResponseId;
123
+ _context.next = 10;
124
+ return getOrgMaterialSurveyResponseGet({
125
+ surveyResponseId: surveyResponseId
126
+ });
127
+ case 10:
128
+ _yield$getOrgMaterial = _context.sent;
129
+ surveyResponse = _yield$getOrgMaterial.surveyResponse;
130
+ setMaterialSurveyResponse(surveyResponse);
131
+ void refreshOrgMaterialSurvey();
132
+ onSubmit(true);
133
+ setSubmitStatus('resolved');
134
+ _context.next = 23;
135
+ break;
136
+ case 18:
137
+ _context.prev = 18;
138
+ _context.t0 = _context["catch"](3);
139
+ console.error(_context.t0);
140
+ onSubmit(false);
141
+ setSubmitStatus('rejected');
142
+ case 23:
143
+ case "end":
144
+ return _context.stop();
145
+ }
146
+ }, _callee, null, [[3, 18]]);
147
+ }));
148
+ return function handleSubmit() {
149
+ return _ref.apply(this, arguments);
150
+ };
151
+ }();
129
152
  return React.createElement(SurveyContentBox, {
130
153
  title: intl.formatMessage({
131
154
  id: 'materialSurvey.myAnswer'
@@ -150,19 +173,20 @@ const MaterialSurveySelectMultiple = () => {
150
173
  })
151
174
  }]
152
175
  }, React.createElement(QuestionCheckbox, {
153
- onSelect: index => {
176
+ onSelect: function onSelect(index) {
154
177
  if (checkUserLectureTestEnded(lecture) || !!userId) {
155
178
  return;
156
179
  }
157
-
158
- setSelectedAnswer(prevState => {
159
- const newState = prevState.includes(index) ? prevState.filter(ident => ident !== index) : [...prevState, index];
180
+ setSelectedAnswer(function (prevState) {
181
+ var newState = prevState.includes(index) ? prevState.filter(function (ident) {
182
+ return ident !== index;
183
+ }) : [].concat(_toConsumableArray(prevState), [index]);
160
184
  return newState;
161
185
  });
162
186
  },
163
187
  selectedOptions: selectedAnswer,
164
188
  disabled: submitStatus === 'pending' || checkUserLectureTestEnded(lecture) || !!userId
165
- }, (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.questionInfoList[0]) ? (_a = materialSurvey.questionInfoList[0].optionInfo) === null || _a === void 0 ? void 0 : _a.map((option, index) => {
189
+ }, (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.questionInfoList[0]) ? (_a = materialSurvey.questionInfoList[0].optionInfo) === null || _a === void 0 ? void 0 : _a.map(function (option, index) {
166
190
  return React.createElement(QuestionCheckboxOption, {
167
191
  key: index,
168
192
  value: index
@@ -1,3 +1,4 @@
1
+ import { slicedToArray as _slicedToArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.js';
1
2
  import React from 'react';
2
3
  import { useIntl } from 'react-intl';
3
4
  import { getOrgMaterialSurveyResponseGet, getOrgMaterialSurveyResponseList, postOrgMaterialSurveyResponseAdd } from '@elice/api-client';
@@ -12,51 +13,56 @@ import { useMaterialSurveyState, useMaterialSurveyDispatch } from './context/Mat
12
13
  import SurveyResultBadge from './SurveyResultBadge.js';
13
14
  import SurveySubmitStatusText from './SurveySubmitStatusText.js';
14
15
 
15
- const MaterialSurveySelectOne = () => {
16
+ var MaterialSurveySelectOne = function MaterialSurveySelectOne() {
16
17
  // 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(() => {
18
+ var _useMaterialSurveySta = useMaterialSurveyState(),
19
+ course = _useMaterialSurveySta.course,
20
+ lecture = _useMaterialSurveySta.lecture,
21
+ materialSurvey = _useMaterialSurveySta.materialSurvey,
22
+ userId = _useMaterialSurveySta.userId;
23
+ var _useMaterialSurveyDis = useMaterialSurveyDispatch(),
24
+ onSubmit = _useMaterialSurveyDis.onSubmit,
25
+ onNext = _useMaterialSurveyDis.onNext,
26
+ refreshOrgMaterialSurvey = _useMaterialSurveyDis.refreshOrgMaterialSurvey;
27
+ // state
28
+ var intl = useIntl();
29
+ var _React$useState = React.useState(),
30
+ _React$useState2 = _slicedToArray(_React$useState, 2),
31
+ selectedAnswer = _React$useState2[0],
32
+ setSelectedAnswer = _React$useState2[1];
33
+ var _React$useState3 = React.useState(),
34
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
35
+ materialSurveyResponse = _React$useState4[0],
36
+ setMaterialSurveyResponse = _React$useState4[1];
37
+ var _React$useState5 = React.useState('idle'),
38
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
39
+ submitStatus = _React$useState6[0],
40
+ setSubmitStatus = _React$useState6[1];
41
+ // survey response fetcher
42
+ React.useEffect(function () {
35
43
  if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
36
- const controller = new AbortController();
37
- const {
38
- signal
39
- } = controller;
44
+ var controller = new AbortController();
45
+ var signal = controller.signal;
40
46
  getOrgMaterialSurveyResponseGet({
41
47
  surveyResponseId: materialSurvey.lastSurveyResponseId
42
48
  }, {
43
- signal
44
- }).then(response => {
49
+ signal: signal
50
+ }).then(function (response) {
45
51
  setMaterialSurveyResponse(response.surveyResponse);
46
52
  setSelectedAnswer(typeof response.surveyResponse.answers[0] === 'string' ? undefined : response.surveyResponse.answers[0][0]);
47
- }).catch(error => {
53
+ }).catch(function (error) {
48
54
  console.error(error);
49
55
  });
50
- return () => controller.abort();
56
+ return function () {
57
+ return controller.abort();
58
+ };
51
59
  }
52
- }, [materialSurvey, userId]); // survey response fetcher
53
-
54
- React.useEffect(() => {
60
+ }, [materialSurvey, userId]);
61
+ // survey response fetcher
62
+ React.useEffect(function () {
55
63
  if (userId && materialSurvey) {
56
- const controller = new AbortController();
57
- const {
58
- signal
59
- } = controller;
64
+ var controller = new AbortController();
65
+ var signal = controller.signal;
60
66
  getOrgMaterialSurveyResponseList({
61
67
  materialSurveyId: materialSurvey.id,
62
68
  filterUserIds: [userId],
@@ -65,50 +71,72 @@ const MaterialSurveySelectOne = () => {
65
71
  offset: 0,
66
72
  count: 1
67
73
  }, {
68
- signal
69
- }).then(response => {
74
+ signal: signal
75
+ }).then(function (response) {
70
76
  var _a;
71
-
72
- const surveyResponse = response.surveyResponses[0];
77
+ var surveyResponse = response.surveyResponses[0];
73
78
  setMaterialSurveyResponse(surveyResponse);
74
79
  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 => {
80
+ }).catch(function (error) {
76
81
  console.error(error);
77
82
  });
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');
83
+ return function () {
84
+ return controller.abort();
85
+ };
109
86
  }
110
- };
111
-
87
+ }, [materialSurvey, userId]);
88
+ // submit handler
89
+ var handleSubmit = /*#__PURE__*/function () {
90
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
91
+ var _yield$postOrgMateria, surveyResponseId, _yield$getOrgMaterial, surveyResponse;
92
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
93
+ while (1) switch (_context.prev = _context.next) {
94
+ case 0:
95
+ if (materialSurvey) {
96
+ _context.next = 2;
97
+ break;
98
+ }
99
+ return _context.abrupt("return");
100
+ case 2:
101
+ setSubmitStatus('pending');
102
+ _context.prev = 3;
103
+ _context.next = 6;
104
+ return postOrgMaterialSurveyResponseAdd({
105
+ materialSurveyId: materialSurvey.id,
106
+ answers: [[selectedAnswer]]
107
+ });
108
+ case 6:
109
+ _yield$postOrgMateria = _context.sent;
110
+ surveyResponseId = _yield$postOrgMateria.surveyResponseId;
111
+ _context.next = 10;
112
+ return getOrgMaterialSurveyResponseGet({
113
+ surveyResponseId: surveyResponseId
114
+ });
115
+ case 10:
116
+ _yield$getOrgMaterial = _context.sent;
117
+ surveyResponse = _yield$getOrgMaterial.surveyResponse;
118
+ setMaterialSurveyResponse(surveyResponse);
119
+ void refreshOrgMaterialSurvey();
120
+ onSubmit(true);
121
+ setSubmitStatus('resolved');
122
+ _context.next = 23;
123
+ break;
124
+ case 18:
125
+ _context.prev = 18;
126
+ _context.t0 = _context["catch"](3);
127
+ console.error(_context.t0);
128
+ onSubmit(false);
129
+ setSubmitStatus('rejected');
130
+ case 23:
131
+ case "end":
132
+ return _context.stop();
133
+ }
134
+ }, _callee, null, [[3, 18]]);
135
+ }));
136
+ return function handleSubmit() {
137
+ return _ref.apply(this, arguments);
138
+ };
139
+ }();
112
140
  return React.createElement(SurveyContentBox, {
113
141
  title: intl.formatMessage({
114
142
  id: 'materialSurvey.myAnswer'
@@ -134,15 +162,14 @@ const MaterialSurveySelectOne = () => {
134
162
  }]
135
163
  }, React.createElement(QuestionRadio, {
136
164
  selectedValue: selectedAnswer,
137
- onSelect: index => {
165
+ onSelect: function onSelect(index) {
138
166
  if (checkUserLectureTestEnded(lecture) || !!userId) {
139
167
  return;
140
168
  }
141
-
142
169
  setSelectedAnswer(index);
143
170
  },
144
171
  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) => {
172
+ }, (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.questionInfoList[0].optionInfo) ? materialSurvey.questionInfoList[0].optionInfo.map(function (option, index) {
146
173
  return React.createElement(QuestionRadioOption, {
147
174
  key: index,
148
175
  value: index
@@ -4,22 +4,21 @@ import { base } from '@elice/design-tokens';
4
4
  import styled from 'styled-components';
5
5
  import { useMaterialSurveyState } from './context/MaterialSurveyContext.js';
6
6
 
7
- const StyledShimmer = styled.div.withConfig({
7
+ var StyledShimmer = styled.div.withConfig({
8
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({
9
+ })(["display:flex;flex-direction:column;border-radius:", ";overflow:hidden;width:100%;"], function (_ref) {
10
+ var vertical = _ref.vertical;
11
+ return vertical ? '0' : '8px';
12
+ });
13
+ var StyledShimmerHeader = styled.div.withConfig({
13
14
  componentId: "sc-1gtcofd-1"
14
15
  })(["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
+ var StyledShimmerBody = styled.div.withConfig({
16
17
  componentId: "sc-1gtcofd-2"
17
18
  })(["padding:1.5rem;background-color:", ";overflow-y:auto;height:100%;"], base.color.navy7);
18
-
19
- const MaterialSurveyShimmer = () => {
20
- const {
21
- vertical
22
- } = useMaterialSurveyState();
19
+ var MaterialSurveyShimmer = function MaterialSurveyShimmer() {
20
+ var _useMaterialSurveySta = useMaterialSurveyState(),
21
+ vertical = _useMaterialSurveySta.vertical;
23
22
  return React.createElement(StyledShimmer, {
24
23
  vertical: vertical
25
24
  }, React.createElement(StyledShimmerHeader, null), React.createElement(StyledShimmerBody, null, React.createElement(Shimmer, {