Skip to content

Commit

Permalink
Merge pull request #47475 from nkdengineer/fix/46960
Browse files Browse the repository at this point in the history
fix: Message of added or invited user to '#admins' chat, doesn't get translated
  • Loading branch information
srikarparsi authored Aug 19, 2024
2 parents a4b5e63 + 9cda525 commit 4757a16
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3838,11 +3838,14 @@ export default {
reimbursementDelayed: `processed the payment but it’s delayed by 1-2 more business days`,
selectedForRandomAudit: `randomly selected for review`,
selectedForRandomAuditMarkdown: `[randomly selected](https://help.expensify.com/articles/expensify-classic/reports/Set-a-random-report-audit-schedule) for review`,
share: ({to}: ShareParams) => `invited user ${to}`,
share: ({to}: ShareParams) => `invited member ${to}`,
unshare: ({to}: UnshareParams) => `removed user ${to}`,
stripePaid: ({amount, currency}: StripePaidParams) => `paid ${currency}${amount}`,
takeControl: `took control`,
unapproved: ({amount, currency}: UnapprovedParams) => `unapproved ${currency}${amount}`,
addEmployee: (email: string, role: string) => `added ${email} as ${role === 'user' ? 'member' : 'admin'}`,
updateRole: (email: string, currentRole: string, newRole: string) => `updated the role of ${email} from ${currentRole} to ${newRole}`,
removeMember: (email: string, role: string) => `removed ${role} ${email}`,
},
},
},
Expand Down
6 changes: 5 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3892,11 +3892,15 @@ export default {
reimbursementDelayed: `procesó el pago pero se retrasó entre 1 y 2 días hábiles más`,
selectedForRandomAudit: `seleccionado al azar para revisión`,
selectedForRandomAuditMarkdown: `[seleccionado al azar](https://help.expensify.com/articles/expensify-classic/reports/Set-a-random-report-audit-schedule) para revisión`,
share: ({to}: ShareParams) => `usuario invitado ${to}`,
share: ({to}: ShareParams) => `miembro invitado ${to}`,
unshare: ({to}: UnshareParams) => `usuario eliminado ${to}`,
stripePaid: ({amount, currency}: StripePaidParams) => `pagado ${currency}${amount}`,
takeControl: `tomó el control`,
unapproved: ({amount, currency}: UnapprovedParams) => `no aprobado ${currency}${amount}`,
addEmployee: (email: string, role: string) => `agregó a ${email} como ${role === 'user' ? 'miembro' : 'administrador'}`,
updateRole: (email: string, currentRole: string, newRole: string) =>
`actualicé el rol ${email} de ${currentRole === 'user' ? 'miembro' : 'administrador'} a ${newRole === 'user' ? 'miembro' : 'administrador'}`,
removeMember: (email: string, role: string) => `eliminado ${role === 'user' ? 'miembro' : 'administrador'} ${email}`,
},
},
},
Expand Down
49 changes: 49 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,52 @@ function getUpdateRoomDescriptionMessage(reportAction: ReportAction): string {
return Localize.translateLocal('roomChangeLog.clearRoomDescription');
}

function isPolicyChangeLogAddEmployeeMessage(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_EMPLOYEE> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_EMPLOYEE);
}

function getPolicyChangeLogAddEmployeeMessage(reportAction: OnyxInputOrEntry<ReportAction>): string {
if (!isPolicyChangeLogAddEmployeeMessage(reportAction)) {
return '';
}

const originalMessage = getOriginalMessage(reportAction);
const email = originalMessage?.email ?? '';
const role = originalMessage?.role ?? '';
return Localize.translateLocal('report.actions.type.addEmployee', email, role);
}

function isPolicyChangeLogChangeRoleMessage(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_EMPLOYEE> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_EMPLOYEE);
}

function getPolicyChangeLogChangeRoleMessage(reportAction: OnyxInputOrEntry<ReportAction>): string {
if (!isPolicyChangeLogChangeRoleMessage(reportAction)) {
return '';
}
const originalMessage = getOriginalMessage(reportAction);
const email = originalMessage?.email ?? '';
const newRole = originalMessage?.newValue ?? '';
const oldRole = originalMessage?.oldValue ?? '';
return Localize.translateLocal('report.actions.type.updateRole', email, oldRole, newRole);
}

function isPolicyChangeLogDeleteMemberMessage(
reportAction: OnyxInputOrEntry<ReportAction>,
): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE);
}

function getPolicyChangeLogDeleteMemberMessage(reportAction: OnyxInputOrEntry<ReportAction>): string {
if (!isPolicyChangeLogDeleteMemberMessage(reportAction)) {
return '';
}
const originalMessage = getOriginalMessage(reportAction);
const email = originalMessage?.email ?? '';
const role = originalMessage?.role ?? '';
return Localize.translateLocal('report.actions.type.removeMember', email, role);
}

function getRenamedAction(reportAction: OnyxEntry<ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.RENAMED>>) {
const initialMessage = getOriginalMessage(reportAction);
return Localize.translateLocal('newRoomPage.renamedRoomAction', {
Expand Down Expand Up @@ -1696,6 +1742,9 @@ export {
getExportIntegrationMessageHTML,
getUpdateRoomDescriptionMessage,
didMessageMentionCurrentUser,
getPolicyChangeLogAddEmployeeMessage,
getPolicyChangeLogChangeRoleMessage,
getPolicyChangeLogDeleteMemberMessage,
getRenamedAction,
};

Expand Down
8 changes: 8 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ function getOptionData({
result.alternateText = ReportUtils.formatReportLastMessageText(Parser.htmlToText(`${lastActorDisplayName}: ${lastMessageText}`));
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG) {
result.alternateText = PolicyUtils.getCleanedTagName(ReportActionsUtils.getReportActionMessage(lastAction)?.text ?? '');
} else if (lastAction && ReportActionsUtils.isOldDotReportAction(lastAction)) {
result.alternateText = ReportActionsUtils.getMessageOfOldDotReportAction(lastAction);
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_EMPLOYEE) {
result.alternateText = ReportActionsUtils.getPolicyChangeLogAddEmployeeMessage(lastAction);
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_EMPLOYEE) {
result.alternateText = ReportActionsUtils.getPolicyChangeLogChangeRoleMessage(lastAction);
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE) {
result.alternateText = ReportActionsUtils.getPolicyChangeLogDeleteMemberMessage(lastAction);
} else {
result.alternateText =
lastMessageTextFromReport.length > 0
Expand Down
6 changes: 6 additions & 0 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ const ContextMenuActions: ContextMenuAction[] = [
setClipboardMessage(ReportActionsUtils.getExportIntegrationMessageHTML(reportAction));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.UPDATE_ROOM_DESCRIPTION) {
setClipboardMessage(ReportActionsUtils.getUpdateRoomDescriptionMessage(reportAction));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_EMPLOYEE) {
setClipboardMessage(ReportActionsUtils.getPolicyChangeLogAddEmployeeMessage(reportAction));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_EMPLOYEE) {
setClipboardMessage(ReportActionsUtils.getPolicyChangeLogChangeRoleMessage(reportAction));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE) {
setClipboardMessage(ReportActionsUtils.getPolicyChangeLogDeleteMemberMessage(reportAction));
} else if (content) {
setClipboardMessage(
content.replace(/(<mention-user>)(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ function ReportActionItem({
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getDismissedViolationMessageText(ReportActionsUtils.getOriginalMessage(action))} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG) {
children = <ReportActionItemBasicMessage message={PolicyUtils.getCleanedTagName(ReportActionsUtils.getReportActionMessage(action)?.text ?? '')} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_EMPLOYEE) {
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getPolicyChangeLogAddEmployeeMessage(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_EMPLOYEE) {
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getPolicyChangeLogChangeRoleMessage(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE) {
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getPolicyChangeLogDeleteMemberMessage(action)} />;
} else if (
ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS)
) {
Expand Down
12 changes: 12 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,20 @@ type OriginalMessageChangeLog = {
/** ID of the report */
reportID?: number;

/** Email of user */
email?: string;

/** Role of user */
role?: string;

/** When was it last modified */
lastModified?: string;

/** New role of user */
newValue?: string;

/** Old role of user */
oldValue?: string;
};

/** Model of `join policy changelog` report action */
Expand Down

0 comments on commit 4757a16

Please sign in to comment.