@@ -1631,7 +1631,7 @@ function createPolicyExpenseChats(
16311631/**
16321632 * Updates a workspace avatar image
16331633 */
1634- function updateWorkspaceAvatar ( policyID : string , file : File ) {
1634+ function updateWorkspaceAvatar ( policyID : string , currentAvatarURL : string | undefined , file : File ) {
16351635 const optimisticData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = [
16361636 {
16371637 onyxMethod : Onyx . METHOD . MERGE ,
@@ -1664,7 +1664,7 @@ function updateWorkspaceAvatar(policyID: string, file: File) {
16641664 onyxMethod : Onyx . METHOD . MERGE ,
16651665 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
16661666 value : {
1667- avatarURL : deprecatedAllPolicies ?. [ ` ${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ?. avatarURL ,
1667+ avatarURL : currentAvatarURL ,
16681668 } ,
16691669 } ,
16701670 ] ;
@@ -1680,10 +1680,7 @@ function updateWorkspaceAvatar(policyID: string, file: File) {
16801680/**
16811681 * Deletes the avatar image for the workspace
16821682 */
1683- function deleteWorkspaceAvatar ( policyID : string ) {
1684- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
1685- // eslint-disable-next-line @typescript-eslint/no-deprecated
1686- const policy = getPolicy ( policyID ) ;
1683+ function deleteWorkspaceAvatar ( policyID : string , currentAvatarURL : string , currentOriginalFileName : string ) {
16871684 const optimisticData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = [
16881685 {
16891686 onyxMethod : Onyx . METHOD . MERGE ,
@@ -1716,8 +1713,8 @@ function deleteWorkspaceAvatar(policyID: string) {
17161713 onyxMethod : Onyx . METHOD . MERGE ,
17171714 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
17181715 value : {
1719- avatarURL : policy ?. avatarURL ,
1720- originalFileName : policy ?. originalFileName ,
1716+ avatarURL : currentAvatarURL ,
1717+ originalFileName : currentOriginalFileName ,
17211718 errorFields : {
17221719 avatarURL : ErrorUtils . getMicroSecondOnyxErrorWithTranslationKey ( 'avatarWithImagePicker.deleteWorkspaceError' ) ,
17231720 } ,
@@ -1748,13 +1745,8 @@ function clearAvatarErrors(policyID: string) {
17481745 * Optimistically update the general settings. Set the general settings as pending until the response succeeds.
17491746 * If the response fails set a general error message. Clear the error message when updating.
17501747 */
1751- function updateGeneralSettings ( policyID : string | undefined , name : string , currencyValue ?: string ) {
1752- if ( ! policyID ) {
1753- return ;
1754- }
1755-
1756- const policy = deprecatedAllPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ;
1757- if ( ! policy ) {
1748+ function updateGeneralSettings ( policy : OnyxEntry < Policy > , name : string , currencyValue ?: string ) {
1749+ if ( ! policy ?. id ) {
17581750 return ;
17591751 }
17601752
@@ -1767,8 +1759,8 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
17671759
17681760 const currentRates = distanceUnit ?. rates ?? { } ;
17691761 const optimisticRates : Record < string , Rate > = { } ;
1770- const finallyRates : Record < string , Rate > = { } ;
1771- const failureRates : Record < string , Rate > = { } ;
1762+ const finallyRates : Record < string , Partial < Rate > > = { } ;
1763+ const failureRates : Record < string , Partial < Rate > > = { } ;
17721764
17731765 if ( customUnitID ) {
17741766 for ( const rateID of Object . keys ( currentRates ) ) {
@@ -1778,13 +1770,10 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
17781770 currency,
17791771 } ;
17801772 finallyRates [ rateID ] = {
1781- ...currentRates [ rateID ] ,
17821773 pendingFields : { currency : null } ,
1783- currency,
17841774 } ;
17851775 failureRates [ rateID ] = {
1786- ...currentRates [ rateID ] ,
1787- pendingFields : { currency : null } ,
1776+ currency : currentRates [ rateID ] . currency ,
17881777 errorFields : { currency : ErrorUtils . getMicroSecondOnyxErrorWithTranslationKey ( 'common.genericErrorMessage' ) } ,
17891778 } ;
17901779 }
@@ -1794,7 +1783,7 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
17941783 {
17951784 // We use SET because it's faster than merge and avoids a race condition when setting the currency and navigating the user to the Bank account page in confirmCurrencyChangeAndHideModal
17961785 onyxMethod : Onyx . METHOD . SET ,
1797- key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
1786+ key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policy . id } ` ,
17981787 value : {
17991788 ...policy ,
18001789
@@ -1826,7 +1815,7 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
18261815 const finallyData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = [
18271816 {
18281817 onyxMethod : Onyx . METHOD . MERGE ,
1829- key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
1818+ key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policy . id } ` ,
18301819 value : {
18311820 pendingFields : {
18321821 name : null ,
@@ -1855,9 +1844,11 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
18551844 const failureData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = [
18561845 {
18571846 onyxMethod : Onyx . METHOD . MERGE ,
1858- key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
1847+ key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policy . id } ` ,
18591848 value : {
18601849 errorFields,
1850+ name : policy . name ,
1851+ outputCurrency : policy . outputCurrency ,
18611852 ...( customUnitID && {
18621853 customUnits : {
18631854 [ customUnitID ] : {
@@ -1871,14 +1862,14 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
18711862 ] ;
18721863
18731864 const params : UpdateWorkspaceGeneralSettingsParams = {
1874- policyID,
1865+ policyID : policy . id ,
18751866 workspaceName : name ,
18761867 currency,
18771868 } ;
18781869
18791870 const persistedRequests = PersistedRequests . getAll ( ) ;
18801871 const createWorkspaceRequestChangedIndex = persistedRequests . findIndex (
1881- ( request ) => request . data ?. policyID === policyID && request . command === WRITE_COMMANDS . CREATE_WORKSPACE && request . data ?. policyName !== name ,
1872+ ( request ) => request . data ?. policyID === policy . id && request . command === WRITE_COMMANDS . CREATE_WORKSPACE && request . data ?. policyName !== name ,
18821873 ) ;
18831874
18841875 const createWorkspaceRequest = persistedRequests . at ( createWorkspaceRequestChangedIndex ) ;
@@ -1890,7 +1881,7 @@ function updateGeneralSettings(policyID: string | undefined, name: string, curre
18901881 policyName : name ,
18911882 } ,
18921883 } ;
1893- Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , {
1884+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policy . id } ` , {
18941885 name,
18951886 } ) ;
18961887
0 commit comments