Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update display name when update legal name #53558

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,8 @@ function isSettled(reportOrID: OnyxInputOrEntry<Report> | SearchReport | string
/**
* Whether the current user is the submitter of the report
*/
function isCurrentUserSubmitter(reportID: string): boolean {
if (!allReports) {
function isCurrentUserSubmitter(reportID: string | undefined): boolean {
if (!allReports || !reportID) {
return false;
}
const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
Expand Down Expand Up @@ -7379,8 +7379,8 @@ function getWorkspaceChats(policyID: string, accountIDs: number[], reports: Onyx
*
* @param policyID - the workspace ID to get all associated reports
*/
function getAllWorkspaceReports(policyID: string): Array<OnyxEntry<Report>> {
return Object.values(allReports ?? {}).filter((report) => (report?.policyID ?? '-1') === policyID);
function getAllWorkspaceReports(policyID: string | undefined): Array<OnyxEntry<Report>> {
return Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,11 +1210,10 @@ function compareDuplicateTransactionFields(
return {keep, change};
}

function getTransactionID(threadReportID: string | undefined): string | undefined {
function getTransactionID(threadReportID?: string): string | undefined {
if (!threadReportID) {
return;
}

const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${threadReportID}`];
const parentReportAction = ReportUtils.isThread(report) ? ReportActionsUtils.getReportAction(report.parentReportID, report.parentReportActionID) : undefined;
const IOUTransactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : undefined;
Expand Down
40 changes: 28 additions & 12 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserEmail = val?.email ?? '';
currentUserAccountID = val?.accountID ?? -1;
currentUserAccountID = val?.accountID ?? CONST.DEFAULT_NUMBER_ID;
},
});

Expand Down Expand Up @@ -121,20 +121,36 @@ function updateDisplayName(firstName: string, lastName: string) {

function updateLegalName(legalFirstName: string, legalLastName: string) {
const parameters: UpdateLegalNameParams = {legalFirstName, legalLastName};

API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
legalFirstName,
legalLastName,
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
legalFirstName,
legalLastName,
},
},
];
// In case the user does not have a display name, we will update the display name based on the legal name
if (!allPersonalDetails?.[currentUserAccountID]?.firstName && !allPersonalDetails?.[currentUserAccountID]?.lastName) {
Themoonalsofall marked this conversation as resolved.
Show resolved Hide resolved
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserAccountID]: {
displayName: PersonalDetailsUtils.createDisplayName(currentUserEmail ?? '', {
firstName: legalFirstName,
lastName: legalLastName,
}),
},
firstName: legalFirstName,
lastName: legalLastName,
},
],
});
}
API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
optimisticData,
});

Navigation.goBack();
}

Expand Down
10 changes: 6 additions & 4 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
const {isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute();
const [isDeleteTaskConfirmModalVisible, setIsDeleteTaskConfirmModalVisible] = React.useState(false);
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || report?.reportID || '-1'}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || report?.reportID}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);

Expand Down Expand Up @@ -100,7 +102,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
const reportDescription = Parser.htmlToText(ReportUtils.getReportDescription(report));
const policyName = ReportUtils.getPolicyName(report, true);
const policyDescription = ReportUtils.getPolicyDescriptionText(policy);
const isPersonalExpenseChat = isPolicyExpenseChat && ReportUtils.isCurrentUserSubmitter(report?.reportID ?? '');
const isPersonalExpenseChat = isPolicyExpenseChat && ReportUtils.isCurrentUserSubmitter(report?.reportID);
const shouldShowSubtitle = () => {
if (!subtitle) {
return false;
Expand Down Expand Up @@ -258,7 +260,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
<PressableWithoutFeedback
onPress={() => {
if (ReportUtils.canEditPolicyDescription(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(report.policyID ?? '-1'));
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(`${report.policyID ?? CONST.DEFAULT_NUMBER_ID}`));
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID, Navigation.getReportRHPActiveRoute()));
Expand Down
Loading