The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/modules/core-apps/nps.module.ts

70 lines
1.0 KiB

import { IUiKitCoreApp } from '../../sdk/types/IUiKitCoreApp';
import { Banner, NPS } from '../../sdk';
import { createModal } from './nps/createModal';
export class Nps implements IUiKitCoreApp {
appId = 'nps-core';
async blockAction(payload: any): Promise<any> {
const {
triggerId,
container: {
id: bannerId,
},
payload: {
value: score,
blockId: npsId,
},
user,
} = payload;
return createModal({
appId: this.appId,
npsId,
bannerId,
triggerId,
score,
user,
});
}
async viewSubmit(payload: any): Promise<any> {
if (!payload.payload?.view?.state) {
throw new Error('Invalid payload');
}
const {
payload: {
view: {
state,
id: bannerId,
},
},
user: {
_id: userId,
roles,
},
} = payload;
const [npsId] = Object.keys(state);
const {
[npsId]: {
score,
comment,
},
} = state;
await NPS.vote({
npsId,
userId,
comment,
roles,
score,
});
await Banner.dismiss(userId, bannerId);
return true;
}
}