feat: add tianji-client-react package and useTianjiSurvey hooks which can easy to get survey info
This commit is contained in:
parent
a596011960
commit
0fc112fc32
@ -17,7 +17,7 @@
|
||||
"build:server": "cd src/server && pnpm build",
|
||||
"build:tracker": "ts-node scripts/build-tracker.ts",
|
||||
"build:geo": "ts-node scripts/build-geo.ts",
|
||||
"build:openapi": "ts-node --project ./tsconfig.base.json ./scripts/build-openapi-schema.ts",
|
||||
"build:openapi": "ts-node --project ./tsconfig.base.json ./scripts/build-openapi-schema.ts && cd packages/client-sdk && pnpm generate:client",
|
||||
"check:type": "pnpm -r check:type",
|
||||
"release": "release-it",
|
||||
"release:patch": "release-it -i patch"
|
||||
|
@ -1,3 +1,4 @@
|
||||
export { initOpenapiSDK } from './config';
|
||||
export { openApiClient } from './open';
|
||||
export * from './tracker';
|
||||
export * from './survey';
|
||||
|
@ -47,7 +47,7 @@ export const OpenAPI: OpenAPIConfig = {
|
||||
PASSWORD: undefined,
|
||||
TOKEN: undefined,
|
||||
USERNAME: undefined,
|
||||
VERSION: '1.9.2',
|
||||
VERSION: '1.9.3',
|
||||
WITH_CREDENTIALS: false,
|
||||
interceptors: {
|
||||
request: new Interceptors(),
|
||||
|
@ -927,10 +927,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyAll(data: $OpenApiTs['/workspace/{workspaceId}/survey//all']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//all']['get']['res'][200]> {
|
||||
public static surveyAll(data: $OpenApiTs['/workspace/{workspaceId}/survey/all']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/all']['get']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'GET',
|
||||
url: '/workspace/{workspaceId}/survey//all',
|
||||
url: '/workspace/{workspaceId}/survey/all',
|
||||
path: {
|
||||
workspaceId: data.workspaceId
|
||||
}
|
||||
@ -944,10 +944,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyGet(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}']['get']['res'][200]> {
|
||||
public static surveyGet(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}']['get']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'GET',
|
||||
url: '/workspace/{workspaceId}/survey//{surveyId}',
|
||||
url: '/workspace/{workspaceId}/survey/{surveyId}',
|
||||
path: {
|
||||
workspaceId: data.workspaceId,
|
||||
surveyId: data.surveyId
|
||||
@ -963,10 +963,10 @@ export class SurveyService {
|
||||
* @returns unknown Error response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyCount(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/count']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/count']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/count']['get']['res'][200]> {
|
||||
public static surveyCount(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/count']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/count']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/count']['get']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'GET',
|
||||
url: '/workspace/{workspaceId}/survey//{surveyId}/count',
|
||||
url: '/workspace/{workspaceId}/survey/{surveyId}/count',
|
||||
path: {
|
||||
workspaceId: data.workspaceId,
|
||||
surveyId: data.surveyId
|
||||
@ -981,10 +981,10 @@ export class SurveyService {
|
||||
* @returns unknown Error response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyAllResultCount(data: $OpenApiTs['/workspace/{workspaceId}/survey//allResultCount']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//allResultCount']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey//allResultCount']['get']['res'][200]> {
|
||||
public static surveyAllResultCount(data: $OpenApiTs['/workspace/{workspaceId}/survey/allResultCount']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/allResultCount']['get']['res'][200] | $OpenApiTs['/workspace/{workspaceId}/survey/allResultCount']['get']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'GET',
|
||||
url: '/workspace/{workspaceId}/survey//allResultCount',
|
||||
url: '/workspace/{workspaceId}/survey/allResultCount',
|
||||
path: {
|
||||
workspaceId: data.workspaceId
|
||||
}
|
||||
@ -999,10 +999,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveySubmit(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/submit']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/submit']['post']['res'][200]> {
|
||||
public static surveySubmit(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/submit']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/submit']['post']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'POST',
|
||||
url: '/workspace/{workspaceId}/survey//{surveyId}/submit',
|
||||
url: '/workspace/{workspaceId}/survey/{surveyId}/submit',
|
||||
path: {
|
||||
workspaceId: data.workspaceId,
|
||||
surveyId: data.surveyId
|
||||
@ -1019,10 +1019,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyCreate(data: $OpenApiTs['/workspace/{workspaceId}/survey//create']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//create']['post']['res'][200]> {
|
||||
public static surveyCreate(data: $OpenApiTs['/workspace/{workspaceId}/survey/create']['post']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/create']['post']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'POST',
|
||||
url: '/workspace/{workspaceId}/survey//create',
|
||||
url: '/workspace/{workspaceId}/survey/create',
|
||||
path: {
|
||||
workspaceId: data.workspaceId
|
||||
},
|
||||
@ -1039,10 +1039,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyUpdate(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/update']['patch']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/update']['patch']['res'][200]> {
|
||||
public static surveyUpdate(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/update']['patch']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/update']['patch']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'PATCH',
|
||||
url: '/workspace/{workspaceId}/survey//{surveyId}/update',
|
||||
url: '/workspace/{workspaceId}/survey/{surveyId}/update',
|
||||
path: {
|
||||
workspaceId: data.workspaceId,
|
||||
surveyId: data.surveyId
|
||||
@ -1059,10 +1059,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyDelete(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/delete']['delete']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/delete']['delete']['res'][200]> {
|
||||
public static surveyDelete(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/delete']['delete']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/delete']['delete']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'DELETE',
|
||||
url: '/workspace/{workspaceId}/survey//{surveyId}/delete',
|
||||
url: '/workspace/{workspaceId}/survey/{surveyId}/delete',
|
||||
path: {
|
||||
workspaceId: data.workspaceId,
|
||||
surveyId: data.surveyId
|
||||
@ -1079,10 +1079,10 @@ export class SurveyService {
|
||||
* @returns unknown Successful response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static surveyResultList(data: $OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/result/list']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey//{surveyId}/result/list']['get']['res'][200]> {
|
||||
public static surveyResultList(data: $OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/result/list']['get']['req']): CancelablePromise<$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}/result/list']['get']['res'][200]> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'GET',
|
||||
url: '/workspace/{workspaceId}/survey//{surveyId}/result/list',
|
||||
url: '/workspace/{workspaceId}/survey/{surveyId}/result/list',
|
||||
path: {
|
||||
workspaceId: data.workspaceId,
|
||||
surveyId: data.surveyId
|
||||
|
@ -439,6 +439,7 @@ export type $OpenApiTs = {
|
||||
payload: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
trendingMode: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
notifications: Array<{
|
||||
@ -469,6 +470,7 @@ export type $OpenApiTs = {
|
||||
payload: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
trendingMode: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
notifications: Array<{
|
||||
@ -497,6 +499,7 @@ export type $OpenApiTs = {
|
||||
payload: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
trendingMode: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
@ -532,6 +535,7 @@ export type $OpenApiTs = {
|
||||
active?: boolean;
|
||||
interval?: number;
|
||||
maxRetries?: number;
|
||||
trendingMode?: boolean;
|
||||
notificationIds?: Array<(string)>;
|
||||
payload: {
|
||||
[key: string]: unknown;
|
||||
@ -554,6 +558,7 @@ export type $OpenApiTs = {
|
||||
payload: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
trendingMode: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
@ -603,6 +608,7 @@ export type $OpenApiTs = {
|
||||
payload: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
trendingMode: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
@ -1091,7 +1097,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//all': {
|
||||
'/workspace/{workspaceId}/survey/all': {
|
||||
get: {
|
||||
req: {
|
||||
workspaceId: string;
|
||||
@ -1118,7 +1124,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//{surveyId}': {
|
||||
'/workspace/{workspaceId}/survey/{surveyId}': {
|
||||
get: {
|
||||
req: {
|
||||
surveyId: string;
|
||||
@ -1146,7 +1152,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//{surveyId}/count': {
|
||||
'/workspace/{workspaceId}/survey/{surveyId}/count': {
|
||||
get: {
|
||||
req: {
|
||||
surveyId: string;
|
||||
@ -1166,7 +1172,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//allResultCount': {
|
||||
'/workspace/{workspaceId}/survey/allResultCount': {
|
||||
get: {
|
||||
req: {
|
||||
workspaceId: string;
|
||||
@ -1185,7 +1191,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//{surveyId}/submit': {
|
||||
'/workspace/{workspaceId}/survey/{surveyId}/submit': {
|
||||
post: {
|
||||
req: {
|
||||
requestBody: {
|
||||
@ -1204,7 +1210,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//create': {
|
||||
'/workspace/{workspaceId}/survey/create': {
|
||||
post: {
|
||||
req: {
|
||||
requestBody: {
|
||||
@ -1242,7 +1248,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//{surveyId}/update': {
|
||||
'/workspace/{workspaceId}/survey/{surveyId}/update': {
|
||||
patch: {
|
||||
req: {
|
||||
requestBody: {
|
||||
@ -1281,7 +1287,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//{surveyId}/delete': {
|
||||
'/workspace/{workspaceId}/survey/{surveyId}/delete': {
|
||||
delete: {
|
||||
req: {
|
||||
surveyId: string;
|
||||
@ -1309,7 +1315,7 @@ export type $OpenApiTs = {
|
||||
};
|
||||
};
|
||||
};
|
||||
'/workspace/{workspaceId}/survey//{surveyId}/result/list': {
|
||||
'/workspace/{workspaceId}/survey/{surveyId}/result/list': {
|
||||
get: {
|
||||
req: {
|
||||
cursor?: string;
|
||||
|
1
packages/client-sdk/src/open/index.ts
Normal file
1
packages/client-sdk/src/open/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * as openApiClient from './client';
|
@ -4,6 +4,8 @@
|
||||
"module": "ESNext",
|
||||
"outDir": "./lib",
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"noEmit": false,
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
|
1
packages/react/.gitignore
vendored
Normal file
1
packages/react/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
lib
|
28
packages/react/package.json
Normal file
28
packages/react/package.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "tianji-client-react",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"prepare": "tsc",
|
||||
"generate:client": "openapi-ts -i ../../website/openapi.json -o src/open/client",
|
||||
"test": "vitest"
|
||||
},
|
||||
"keywords": [
|
||||
"tianji"
|
||||
],
|
||||
"author": "moonrailgun <moonrailgun@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tianji-client-sdk": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.22",
|
||||
"react": "^18.3.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18.2.22",
|
||||
"react": "^18.3.1"
|
||||
}
|
||||
}
|
1
packages/react/src/index.ts
Normal file
1
packages/react/src/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './useTianjiSurvey';
|
38
packages/react/src/useTianjiSurvey.ts
Normal file
38
packages/react/src/useTianjiSurvey.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
initOpenapiSDK,
|
||||
getSurveyInfo,
|
||||
openApiClient,
|
||||
} from 'tianji-client-sdk';
|
||||
|
||||
type SurveyInfo =
|
||||
openApiClient.$OpenApiTs['/workspace/{workspaceId}/survey/{surveyId}']['get']['res']['200'];
|
||||
|
||||
interface UseTianjiSurveyOptions {
|
||||
baseUrl?: string;
|
||||
workspaceId: string;
|
||||
surveyId: string;
|
||||
}
|
||||
export function useTianjiSurvey(options: UseTianjiSurveyOptions) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [info, setInfo] = useState<SurveyInfo | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if (options.baseUrl) {
|
||||
initOpenapiSDK(options.baseUrl);
|
||||
}
|
||||
}, [options.baseUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true);
|
||||
getSurveyInfo(options.workspaceId, options.surveyId)
|
||||
.then((data) => {
|
||||
setInfo(data);
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, [options.workspaceId, options.surveyId]);
|
||||
|
||||
return { isLoading, info };
|
||||
}
|
10
packages/react/tsconfig.json
Normal file
10
packages/react/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"outDir": "./lib",
|
||||
"baseUrl": ".",
|
||||
"noEmit": false,
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
}
|
@ -86,6 +86,19 @@ importers:
|
||||
specifier: ^1.2.1
|
||||
version: 1.2.1(@types/node@18.17.12)(happy-dom@14.7.1)
|
||||
|
||||
packages/react:
|
||||
dependencies:
|
||||
tianji-client-sdk:
|
||||
specifier: workspace:^
|
||||
version: link:../client-sdk
|
||||
devDependencies:
|
||||
'@types/react':
|
||||
specifier: ^18.2.22
|
||||
version: 18.2.78
|
||||
react:
|
||||
specifier: ^18.3.1
|
||||
version: 18.3.1
|
||||
|
||||
src/client:
|
||||
dependencies:
|
||||
'@ant-design/charts':
|
||||
@ -23718,6 +23731,13 @@ packages:
|
||||
loose-envify: 1.4.0
|
||||
dev: false
|
||||
|
||||
/react@18.3.1:
|
||||
resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dependencies:
|
||||
loose-envify: 1.4.0
|
||||
dev: true
|
||||
|
||||
/reactcss@1.2.3(react@18.2.0):
|
||||
resolution: {integrity: sha512-KiwVUcFu1RErkI97ywr8nvx8dNOpT03rbnma0SSalTYjkrPYaEajR4a/MRt6DZ46K6arDRbWMNHF+xH7G7n/8A==}
|
||||
peerDependencies:
|
||||
|
@ -292,7 +292,7 @@ function buildSurveyOpenapi(meta: OpenApiMetaInfo): OpenApiMeta {
|
||||
tags: [OPENAPI_TAG.SURVEY],
|
||||
protect: true,
|
||||
...meta,
|
||||
path: `/workspace/{workspaceId}/survey/${meta.path}`,
|
||||
path: `/workspace/{workspaceId}/survey${meta.path}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user