@o2s/modules.surveyjs 0.4.0 → 0.4.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/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @o2s/modules.surveyjs
|
|
2
|
+
|
|
3
|
+
A module that handles fetching, rendering and submitting SurveyJS-based forms.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @o2s/modules.surveyjs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Backend (API Harmonization)
|
|
14
|
+
|
|
15
|
+
Register the module in `app.module.ts`:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import * as SurveyJs from '@o2s/modules.surveyjs/api-harmonization';
|
|
19
|
+
import { AppConfig } from './app.config';
|
|
20
|
+
|
|
21
|
+
@Module({
|
|
22
|
+
imports: [
|
|
23
|
+
SurveyJs.Module.register(AppConfig),
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
export class AppModule {}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Frontend
|
|
30
|
+
|
|
31
|
+
Use the SurveyJS components:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { SurveyJsRenderer } from '@o2s/modules.surveyjs/frontend';
|
|
35
|
+
|
|
36
|
+
export const SurveyPage = async ({ surveyId }) => {
|
|
37
|
+
return <SurveyJsRenderer surveyId={surveyId} />;
|
|
38
|
+
};
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### SDK
|
|
42
|
+
|
|
43
|
+
The SDK exports a pre-configured instance (uses `NEXT_PUBLIC_API_URL` for the API base URL):
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { sdk } from '@o2s/modules.surveyjs/sdk';
|
|
47
|
+
|
|
48
|
+
// Fetch survey (code is the survey identifier from CMS)
|
|
49
|
+
const survey = await sdk.modules.getSurvey({ code: surveyCode }, { 'x-locale': 'en' }, accessToken);
|
|
50
|
+
|
|
51
|
+
// Submit survey
|
|
52
|
+
await sdk.modules.submitSurvey(
|
|
53
|
+
{ code: surveyCode, surveyPayload: answers },
|
|
54
|
+
{ 'x-locale': 'en' },
|
|
55
|
+
accessToken,
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
This module requires CMS integration to be configured in `AppConfig`:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { CMS } from '@o2s/configs.integrations';
|
|
65
|
+
|
|
66
|
+
export const AppConfig: ApiConfig = {
|
|
67
|
+
integrations: {
|
|
68
|
+
cms: CMS.CmsIntegrationConfig,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Related Packages
|
|
74
|
+
|
|
75
|
+
- `@o2s/blocks.surveyjs-form` - SurveyJS form block
|
|
76
|
+
- `@o2s/configs.integrations` - Integration configuration
|
|
77
|
+
- `survey-core` - SurveyJS core library
|
|
78
|
+
- `survey-react-ui` - SurveyJS React UI components
|