@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,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var blocks = require('@elice/blocks');
|
|
5
|
+
var designTokens = require('@elice/design-tokens');
|
|
6
|
+
var styled = require('styled-components');
|
|
7
|
+
var MaterialSurveyContext = require('./context/MaterialSurveyContext.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
13
|
+
|
|
14
|
+
const StyledShimmer = styled__default["default"].div.withConfig({
|
|
15
|
+
componentId: "sc-1gtcofd-0"
|
|
16
|
+
})(["display:flex;flex-direction:column;border-radius:", ";overflow:hidden;width:100%;"], ({
|
|
17
|
+
vertical
|
|
18
|
+
}) => vertical ? '0' : '8px');
|
|
19
|
+
const StyledShimmerHeader = styled__default["default"].div.withConfig({
|
|
20
|
+
componentId: "sc-1gtcofd-1"
|
|
21
|
+
})(["display:flex;justify-content:space-between;background-color:", ";padding:1rem 1.5rem;height:3.5rem;"], designTokens.base.color.navy6);
|
|
22
|
+
const StyledShimmerBody = styled__default["default"].div.withConfig({
|
|
23
|
+
componentId: "sc-1gtcofd-2"
|
|
24
|
+
})(["padding:1.5rem;background-color:", ";overflow-y:auto;height:100%;"], designTokens.base.color.navy7);
|
|
25
|
+
|
|
26
|
+
const MaterialSurveyShimmer = () => {
|
|
27
|
+
const {
|
|
28
|
+
vertical
|
|
29
|
+
} = MaterialSurveyContext.useMaterialSurveyState();
|
|
30
|
+
return React__default["default"].createElement(StyledShimmer, {
|
|
31
|
+
vertical: vertical
|
|
32
|
+
}, React__default["default"].createElement(StyledShimmerHeader, null), React__default["default"].createElement(StyledShimmerBody, null, React__default["default"].createElement(blocks.Shimmer, {
|
|
33
|
+
dark: true,
|
|
34
|
+
borderRadius: '4px',
|
|
35
|
+
width: "80%",
|
|
36
|
+
height: '40px'
|
|
37
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
38
|
+
height: 1
|
|
39
|
+
}), React__default["default"].createElement(blocks.Shimmer, {
|
|
40
|
+
dark: true,
|
|
41
|
+
borderRadius: '4px',
|
|
42
|
+
width: "100%",
|
|
43
|
+
height: '40px'
|
|
44
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
45
|
+
height: 1
|
|
46
|
+
}), React__default["default"].createElement(blocks.Shimmer, {
|
|
47
|
+
dark: true,
|
|
48
|
+
borderRadius: '4px',
|
|
49
|
+
width: "100%",
|
|
50
|
+
height: '40px'
|
|
51
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
52
|
+
height: 1
|
|
53
|
+
}), React__default["default"].createElement(blocks.Shimmer, {
|
|
54
|
+
dark: true,
|
|
55
|
+
borderRadius: '4px',
|
|
56
|
+
width: "100%",
|
|
57
|
+
height: '40px'
|
|
58
|
+
})));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = MaterialSurveyShimmer;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var apiClient = require('@elice/api-client');
|
|
6
|
+
var designTokens = require('@elice/design-tokens');
|
|
7
|
+
var styled = require('styled-components');
|
|
8
|
+
var index = require('../../helpers/index.js');
|
|
9
|
+
var SurveyContentBox = require('../shared/SurveyContentBox.js');
|
|
10
|
+
var MaterialSurveyContext = require('./context/MaterialSurveyContext.js');
|
|
11
|
+
var SurveyResultBadge = require('./SurveyResultBadge.js');
|
|
12
|
+
var SurveySubmitStatusText = require('./SurveySubmitStatusText.js');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
17
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
18
|
+
|
|
19
|
+
const StyledTextarea = styled__default["default"].textarea.withConfig({
|
|
20
|
+
componentId: "sc-16tkulg-0"
|
|
21
|
+
})(["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, ({
|
|
22
|
+
disabled
|
|
23
|
+
}) => disabled ? 'not-allowed' : 'text');
|
|
24
|
+
|
|
25
|
+
const MaterialSurveyText = () => {
|
|
26
|
+
// context
|
|
27
|
+
const {
|
|
28
|
+
lecture,
|
|
29
|
+
materialSurvey,
|
|
30
|
+
userId
|
|
31
|
+
} = MaterialSurveyContext.useMaterialSurveyState();
|
|
32
|
+
const {
|
|
33
|
+
onSubmit,
|
|
34
|
+
onNext,
|
|
35
|
+
refreshOrgMaterialSurvey
|
|
36
|
+
} = MaterialSurveyContext.useMaterialSurveyDispatch(); // state
|
|
37
|
+
|
|
38
|
+
const intl = reactIntl.useIntl();
|
|
39
|
+
const [materialSurveyResponse, setMaterialSurveyResponse] = React__default["default"].useState();
|
|
40
|
+
const [submitStatus, setSubmitStatus] = React__default["default"].useState('idle');
|
|
41
|
+
const [answer, setAnswer] = React__default["default"].useState(''); // survey response fetcher
|
|
42
|
+
|
|
43
|
+
React__default["default"].useEffect(() => {
|
|
44
|
+
if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const {
|
|
47
|
+
signal
|
|
48
|
+
} = controller;
|
|
49
|
+
apiClient.getOrgMaterialSurveyResponseGet({
|
|
50
|
+
surveyResponseId: materialSurvey.lastSurveyResponseId
|
|
51
|
+
}, {
|
|
52
|
+
signal
|
|
53
|
+
}).then(response => {
|
|
54
|
+
setMaterialSurveyResponse(response.surveyResponse);
|
|
55
|
+
setAnswer(response.surveyResponse.answers[0]);
|
|
56
|
+
}).catch(error => {
|
|
57
|
+
console.error(error);
|
|
58
|
+
});
|
|
59
|
+
return () => controller.abort();
|
|
60
|
+
}
|
|
61
|
+
}, [materialSurvey, userId]); // survey response fetcher
|
|
62
|
+
|
|
63
|
+
React__default["default"].useEffect(() => {
|
|
64
|
+
if (userId && materialSurvey) {
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const {
|
|
67
|
+
signal
|
|
68
|
+
} = controller;
|
|
69
|
+
apiClient.getOrgMaterialSurveyResponseList({
|
|
70
|
+
materialSurveyId: materialSurvey.id,
|
|
71
|
+
filterUserIds: [userId],
|
|
72
|
+
isContainOnlyLast: true,
|
|
73
|
+
isIncludeAnswer: true,
|
|
74
|
+
offset: 0,
|
|
75
|
+
count: 1
|
|
76
|
+
}, {
|
|
77
|
+
signal
|
|
78
|
+
}).then(response => {
|
|
79
|
+
const surveyResponse = response.surveyResponses[0];
|
|
80
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
81
|
+
setAnswer(typeof (surveyResponse === null || surveyResponse === void 0 ? void 0 : surveyResponse.answers[0]) === 'string' ? surveyResponse.answers[0] : '');
|
|
82
|
+
}).catch(error => {
|
|
83
|
+
console.error(error);
|
|
84
|
+
});
|
|
85
|
+
return () => controller.abort();
|
|
86
|
+
}
|
|
87
|
+
}, [materialSurvey, userId]); // submit handler
|
|
88
|
+
|
|
89
|
+
const handleSubmit = async () => {
|
|
90
|
+
if (!materialSurvey) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setSubmitStatus('pending');
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const {
|
|
98
|
+
surveyResponseId
|
|
99
|
+
} = await apiClient.postOrgMaterialSurveyResponseAdd({
|
|
100
|
+
materialSurveyId: materialSurvey.id,
|
|
101
|
+
answers: [answer]
|
|
102
|
+
});
|
|
103
|
+
const {
|
|
104
|
+
surveyResponse
|
|
105
|
+
} = await apiClient.getOrgMaterialSurveyResponseGet({
|
|
106
|
+
surveyResponseId
|
|
107
|
+
});
|
|
108
|
+
setMaterialSurveyResponse(surveyResponse);
|
|
109
|
+
void refreshOrgMaterialSurvey();
|
|
110
|
+
onSubmit(true);
|
|
111
|
+
setSubmitStatus('resolved');
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error(error);
|
|
114
|
+
onSubmit(false);
|
|
115
|
+
setSubmitStatus('rejected');
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const commonProps = {
|
|
120
|
+
type: 'text',
|
|
121
|
+
autoFocus: answer.length === 0,
|
|
122
|
+
disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId,
|
|
123
|
+
placeholder: intl.formatMessage({
|
|
124
|
+
id: 'materialSurvey.text.placeholder'
|
|
125
|
+
}),
|
|
126
|
+
value: answer,
|
|
127
|
+
onChange: e => {
|
|
128
|
+
setAnswer(e.target.value);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
return React__default["default"].createElement(SurveyContentBox["default"], {
|
|
132
|
+
title: intl.formatMessage({
|
|
133
|
+
id: 'materialSurvey.myAnswer'
|
|
134
|
+
}),
|
|
135
|
+
onNext: onNext,
|
|
136
|
+
submitResult: React__default["default"].createElement(SurveyResultBadge, {
|
|
137
|
+
materialSurveyResponse: materialSurveyResponse
|
|
138
|
+
}),
|
|
139
|
+
submitStatus: React__default["default"].createElement(SurveySubmitStatusText, {
|
|
140
|
+
status: submitStatus
|
|
141
|
+
}),
|
|
142
|
+
footerActions: [{
|
|
143
|
+
border: true,
|
|
144
|
+
children: intl.formatMessage({
|
|
145
|
+
id: 'materialSurvey.submit'
|
|
146
|
+
}),
|
|
147
|
+
disabled: answer.length === 0 || index.checkUserLectureTestEnded(lecture) || !!userId,
|
|
148
|
+
loading: submitStatus === 'pending',
|
|
149
|
+
tabIndex: 0,
|
|
150
|
+
transparent: false,
|
|
151
|
+
role: 'primary',
|
|
152
|
+
onClick: handleSubmit
|
|
153
|
+
}]
|
|
154
|
+
}, React__default["default"].createElement(StyledTextarea, Object.assign({
|
|
155
|
+
id: "survey-text-answer"
|
|
156
|
+
}, commonProps)));
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
module.exports = MaterialSurveyText;
|
|
@@ -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,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var blocks = require('@elice/blocks');
|
|
6
|
+
var index = require('../../helpers/index.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
11
|
+
|
|
12
|
+
const SurveyResultBadge = ({
|
|
13
|
+
materialSurveyResponse
|
|
14
|
+
}) => {
|
|
15
|
+
const intl = reactIntl.useIntl();
|
|
16
|
+
const status = React__default["default"].useMemo(() => index.getSurveyResultStatus(materialSurveyResponse), [materialSurveyResponse]);
|
|
17
|
+
|
|
18
|
+
switch (status) {
|
|
19
|
+
case index.SurveyResultStatus.Submitted:
|
|
20
|
+
return React__default["default"].createElement(blocks.BadgeNext, {
|
|
21
|
+
type: "quiet",
|
|
22
|
+
role: "primary"
|
|
23
|
+
}, intl.formatMessage({
|
|
24
|
+
id: 'materialSurvey.resultStatus.submitted'
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
default:
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = SurveyResultBadge;
|
|
@@ -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,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var blocks = require('@elice/blocks');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
+
|
|
11
|
+
const SurveySubmitStatusText = ({
|
|
12
|
+
status
|
|
13
|
+
}) => {
|
|
14
|
+
const intl = reactIntl.useIntl();
|
|
15
|
+
|
|
16
|
+
switch (status) {
|
|
17
|
+
case 'resolved':
|
|
18
|
+
return React__default["default"].createElement(blocks.StatusText, {
|
|
19
|
+
role: "success",
|
|
20
|
+
size: "small"
|
|
21
|
+
}, intl.formatMessage({
|
|
22
|
+
id: 'materialSurvey.submitStatus.success'
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
case 'rejected':
|
|
26
|
+
return React__default["default"].createElement(blocks.StatusText, {
|
|
27
|
+
role: "danger",
|
|
28
|
+
size: "small"
|
|
29
|
+
}, intl.formatMessage({
|
|
30
|
+
id: 'materialSurvey.submitStatus.failure'
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
default:
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = SurveySubmitStatusText;
|
|
@@ -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,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var apiClient = require('@elice/api-client');
|
|
7
|
+
var materialSharedUtils = require('@elice/material-shared-utils');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
|
|
13
|
+
const StateContext = React__default["default"].createContext(undefined);
|
|
14
|
+
const DispatchContext = React__default["default"].createContext(undefined);
|
|
15
|
+
StateContext.displayName = 'MaterialSurveyStateContext';
|
|
16
|
+
DispatchContext.displayName = 'MaterialSurveyDispatchContext';
|
|
17
|
+
|
|
18
|
+
function MaterialSurveyProvider({
|
|
19
|
+
materialSurveyId,
|
|
20
|
+
userId,
|
|
21
|
+
onSubmit = () => void 0,
|
|
22
|
+
onNext,
|
|
23
|
+
children
|
|
24
|
+
}) {
|
|
25
|
+
const [course, setCourse] = React__default["default"].useState();
|
|
26
|
+
const [lecture, setLecture] = React__default["default"].useState();
|
|
27
|
+
const [materialSurvey, setMaterialSurvey] = React__default["default"].useState();
|
|
28
|
+
const [initStatus, setInitStatus] = React__default["default"].useState('idle');
|
|
29
|
+
const [vertical, setVertical] = React__default["default"].useState(false);
|
|
30
|
+
const canInit = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
|
|
31
|
+
const doInitilize = React__default["default"].useCallback(async () => {
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const {
|
|
34
|
+
signal
|
|
35
|
+
} = controller;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
setInitStatus('pending'); // fetch materialSurvey
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
materialSurvey
|
|
42
|
+
} = await apiClient.getOrgMaterialSurveyGet({
|
|
43
|
+
materialSurveyId
|
|
44
|
+
}, {
|
|
45
|
+
signal
|
|
46
|
+
}); // fetch course
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
course
|
|
50
|
+
} = await apiClient.getOrgCourseGet({
|
|
51
|
+
courseId: materialSurvey.courseId
|
|
52
|
+
}, {
|
|
53
|
+
signal
|
|
54
|
+
}); // fetch lecture
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
lecture
|
|
58
|
+
} = await apiClient.getOrgLectureGet({
|
|
59
|
+
lectureId: materialSurvey.lectureId
|
|
60
|
+
}, {
|
|
61
|
+
signal
|
|
62
|
+
});
|
|
63
|
+
setMaterialSurvey(materialSurvey);
|
|
64
|
+
setCourse(course);
|
|
65
|
+
setLecture(lecture);
|
|
66
|
+
setInitStatus('resolved');
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(error);
|
|
69
|
+
setInitStatus('rejected');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return () => controller.abort();
|
|
73
|
+
}, [materialSurveyId]);
|
|
74
|
+
React__default["default"].useEffect(() => {
|
|
75
|
+
if (canInit) {
|
|
76
|
+
void doInitilize();
|
|
77
|
+
}
|
|
78
|
+
}, [canInit, doInitilize]); //
|
|
79
|
+
//
|
|
80
|
+
// materialSurvey refresher
|
|
81
|
+
|
|
82
|
+
const refreshOrgMaterialSurvey = React__default["default"].useCallback(signal => {
|
|
83
|
+
return apiClient.getOrgMaterialSurveyGet({
|
|
84
|
+
materialSurveyId
|
|
85
|
+
}, {
|
|
86
|
+
signal
|
|
87
|
+
}).then(response => {
|
|
88
|
+
setMaterialSurvey(response.materialSurvey);
|
|
89
|
+
}).catch(error => {
|
|
90
|
+
console.error(error);
|
|
91
|
+
});
|
|
92
|
+
}, [materialSurveyId]);
|
|
93
|
+
return React__default["default"].createElement(StateContext.Provider, {
|
|
94
|
+
value: {
|
|
95
|
+
course,
|
|
96
|
+
lecture,
|
|
97
|
+
materialSurvey,
|
|
98
|
+
userId,
|
|
99
|
+
vertical,
|
|
100
|
+
initStatus
|
|
101
|
+
}
|
|
102
|
+
}, React__default["default"].createElement(DispatchContext.Provider, {
|
|
103
|
+
value: {
|
|
104
|
+
onSubmit,
|
|
105
|
+
onNext,
|
|
106
|
+
refreshOrgMaterialSurvey,
|
|
107
|
+
setVertical
|
|
108
|
+
}
|
|
109
|
+
}, children));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function useMaterialSurveyState() {
|
|
113
|
+
const context = React__default["default"].useContext(StateContext);
|
|
114
|
+
|
|
115
|
+
if (context === undefined) {
|
|
116
|
+
throw new Error('useMaterialSurveyState must be used within a MaterialSurveyProvider');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return context;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function useMaterialSurveyDispatch() {
|
|
123
|
+
const context = React__default["default"].useContext(DispatchContext);
|
|
124
|
+
|
|
125
|
+
if (context === undefined) {
|
|
126
|
+
throw new Error('useMaterialSurveyDispatch must be used within a MaterialSurveyProvider');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return context;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
exports.MaterialSurveyProvider = MaterialSurveyProvider;
|
|
133
|
+
exports.useMaterialSurveyDispatch = useMaterialSurveyDispatch;
|
|
134
|
+
exports.useMaterialSurveyState = 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;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactHookForm = require('react-hook-form');
|
|
5
|
+
var reactIntl = require('react-intl');
|
|
6
|
+
var reactUse = require('react-use');
|
|
7
|
+
var editValue = require('./utils/editValue.js');
|
|
8
|
+
var context = require('./context.js');
|
|
9
|
+
var locales = require('./locales.js');
|
|
10
|
+
var MaterialSurveyEditContent = require('./MaterialSurveyEditContent.js');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
15
|
+
|
|
16
|
+
const MaterialSurveyEdit = React.forwardRef(({
|
|
17
|
+
value,
|
|
18
|
+
disabled = false,
|
|
19
|
+
locale = 'en',
|
|
20
|
+
onChange,
|
|
21
|
+
onFormStateChange,
|
|
22
|
+
onFileUploadRequest
|
|
23
|
+
}, ref) => {
|
|
24
|
+
const formElRef = React__default["default"].useRef(null);
|
|
25
|
+
const useFormMethods = reactHookForm.useForm({
|
|
26
|
+
defaultValues: editValue.manipulateValue(value),
|
|
27
|
+
mode: 'onBlur'
|
|
28
|
+
});
|
|
29
|
+
const watchedMaterialSurveyEditValue = useFormMethods.watch();
|
|
30
|
+
const {
|
|
31
|
+
isDirty,
|
|
32
|
+
isValid
|
|
33
|
+
} = useFormMethods.formState; //
|
|
34
|
+
// Reset from value, when `value` changes.
|
|
35
|
+
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
36
|
+
//
|
|
37
|
+
|
|
38
|
+
reactUse.useDeepCompareEffect(() => {
|
|
39
|
+
useFormMethods.reset(editValue.manipulateValue(value), {
|
|
40
|
+
keepDirty: true,
|
|
41
|
+
keepErrors: true,
|
|
42
|
+
keepIsValid: true,
|
|
43
|
+
keepTouched: true,
|
|
44
|
+
keepValues: true
|
|
45
|
+
});
|
|
46
|
+
void useFormMethods.trigger();
|
|
47
|
+
}, [value]); //
|
|
48
|
+
// Emit `onChange` handler when form value changed.
|
|
49
|
+
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
50
|
+
//
|
|
51
|
+
|
|
52
|
+
reactUse.useDeepCompareEffect(() => onChange(editValue.restoreValue(watchedMaterialSurveyEditValue)), [watchedMaterialSurveyEditValue]); //
|
|
53
|
+
// Emit `onFormStateChange` handler when form state change.
|
|
54
|
+
//
|
|
55
|
+
|
|
56
|
+
React__default["default"].useEffect(() => {
|
|
57
|
+
if (typeof onFormStateChange === 'function') {
|
|
58
|
+
onFormStateChange({
|
|
59
|
+
isDirty,
|
|
60
|
+
isValid
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
[isDirty, isValid]); //
|
|
65
|
+
// Set ref.
|
|
66
|
+
//
|
|
67
|
+
|
|
68
|
+
React__default["default"].useImperativeHandle(ref, () => Object.assign(Object.assign({}, formElRef.current), {
|
|
69
|
+
reset: () => {
|
|
70
|
+
useFormMethods.reset(editValue.manipulateValue(value));
|
|
71
|
+
void useFormMethods.trigger();
|
|
72
|
+
}
|
|
73
|
+
}), [useFormMethods, value]); //
|
|
74
|
+
//
|
|
75
|
+
//
|
|
76
|
+
|
|
77
|
+
return React__default["default"].createElement("form", {
|
|
78
|
+
ref: formElRef
|
|
79
|
+
}, React__default["default"].createElement(context["default"].Provider, {
|
|
80
|
+
value: {
|
|
81
|
+
disabled,
|
|
82
|
+
onFileUploadRequest
|
|
83
|
+
}
|
|
84
|
+
}, React__default["default"].createElement(reactIntl.IntlProvider, {
|
|
85
|
+
locale: locale,
|
|
86
|
+
defaultLocale: "en",
|
|
87
|
+
messages: locale in locales ? locales[locale] : locales.en
|
|
88
|
+
}, React__default["default"].createElement(reactHookForm.FormProvider, Object.assign({}, useFormMethods), React__default["default"].createElement(MaterialSurveyEditContent, null)))));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
module.exports = MaterialSurveyEdit;
|