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

Implement offline behavior and error handling for UpdateGroupChatName #41826

Merged
merged 8 commits into from
May 28, 2024
Merged
2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ const CONST = {
LOGIN_CHARACTER_LIMIT: 254,
CATEGORY_NAME_LIMIT: 256,
TAG_NAME_LIMIT: 256,
REPORT_NAME_LIMIT: 256,
REPORT_NAME_LIMIT: 100,
TITLE_CHARACTER_LIMIT: 100,
DESCRIPTION_LIMIT: 500,
WORKSPACE_NAME_CHARACTER_LIMIT: 80,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function isValidCompanyName(name: string) {
}

function isValidReportName(name: string) {
return name.trim().length < CONST.REPORT_NAME_LIMIT;
return name.trim().length <= CONST.REPORT_NAME_LIMIT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update CONST.REPORT_NAME_LIMIT check #39984 (comment)

}

/**
Expand Down
33 changes: 32 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {prepareDraftComment} from '@libs/DraftCommentUtils';
import * as EmojiUtils from '@libs/EmojiUtils';
import * as Environment from '@libs/Environment/Environment';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as Localize from '@libs/Localize';
import Log from '@libs/Log';
import * as LoginUtils from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -636,14 +637,44 @@ function updateGroupChatName(reportID: string, reportName: string) {
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
reportName,
pendingFields: {
reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
reportName: null,
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
pendingFields: {
reportName: null,
},
},
},
];
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
reportName: currentReportData?.[reportID]?.reportName ?? null,
errors: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capturing error should be based on errorFields but since we depended on errors this resulted in issue #42765

reportName: Localize.translateLocal('common.genericErrorMessage'),
},
pendingFields: {
reportName: null,
},
},
},
];
const parameters: UpdateGroupChatNameParams = {reportName, reportID};
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData});
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData, successData, failureData});
}

function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageManipulatorResult) {
Expand Down
Loading