11import Onyx from 'react-native-onyx' ;
2- import type { OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
2+ import type { OnyxUpdate } from 'react-native-onyx' ;
33import * as API from '@libs/API' ;
44import type { AddSchoolPrincipalParams , ReferTeachersUniteVolunteerParams } from '@libs/API/parameters' ;
55import { WRITE_COMMANDS } from '@libs/API/types' ;
66import Navigation from '@libs/Navigation/Navigation' ;
7- import * as PhoneNumber from '@libs/PhoneNumber' ;
7+ import { addSMSDomainIfPhoneNumber } from '@libs/PhoneNumber' ;
88import { getPolicy } from '@libs/PolicyUtils' ;
9- import * as ReportUtils from '@libs/ReportUtils' ;
9+ import { buildOptimisticChatReport , buildOptimisticCreatedReportAction } from '@libs/ReportUtils' ;
1010import type { OptimisticCreatedReportAction } from '@libs/ReportUtils' ;
1111import CONST from '@src/CONST' ;
1212import ONYXKEYS from '@src/ONYXKEYS' ;
13- import type { PersonalDetailsList } from '@src/types/onyx' ;
1413
1514type CreationData = {
1615 reportID : string ;
@@ -21,27 +20,11 @@ type ReportCreationData = Record<string, CreationData>;
2120
2221type ExpenseReportActionData = Record < string , OptimisticCreatedReportAction > ;
2322
24- let sessionEmail = '' ;
25- let sessionAccountID = 0 ;
26- Onyx . connect ( {
27- key : ONYXKEYS . SESSION ,
28- callback : ( value ) => {
29- sessionEmail = value ?. email ?? '' ;
30- sessionAccountID = value ?. accountID ?? CONST . DEFAULT_NUMBER_ID ;
31- } ,
32- } ) ;
33-
34- let allPersonalDetails : OnyxEntry < PersonalDetailsList > ;
35- Onyx . connect ( {
36- key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
37- callback : ( value ) => ( allPersonalDetails = value ) ,
38- } ) ;
39-
4023/**
4124 * @param publicRoomReportID - This is the global reportID for the public room, we'll ignore the optimistic one
4225 */
4326function referTeachersUniteVolunteer ( partnerUserID : string , firstName : string , lastName : string , policyID : string , publicRoomReportID : string ) {
44- const optimisticPublicRoom = ReportUtils . buildOptimisticChatReport ( {
27+ const optimisticPublicRoom = buildOptimisticChatReport ( {
4528 participantList : [ ] ,
4629 reportName : CONST . TEACHERS_UNITE . PUBLIC_ROOM_NAME ,
4730 chatType : CONST . REPORT . CHAT_TYPE . POLICY_ROOM ,
@@ -80,12 +63,20 @@ function referTeachersUniteVolunteer(partnerUserID: string, firstName: string, l
8063/**
8164 * Optimistically creates a policyExpenseChat for the school principal and passes data to AddSchoolPrincipal
8265 */
83- function addSchoolPrincipal ( firstName : string , partnerUserID : string , lastName : string , policyID : string ) {
66+ function addSchoolPrincipal (
67+ firstName : string ,
68+ partnerUserID : string ,
69+ lastName : string ,
70+ policyID : string ,
71+ localCurrencyCode : string | undefined ,
72+ sessionEmail : string ,
73+ sessionAccountID : number ,
74+ ) {
8475 const policyName = CONST . TEACHERS_UNITE . POLICY_NAME ;
85- const loggedInEmail = PhoneNumber . addSMSDomainIfPhoneNumber ( sessionEmail ) ;
76+ const loggedInEmail = addSMSDomainIfPhoneNumber ( sessionEmail ) ;
8677 const reportCreationData : ReportCreationData = { } ;
8778
88- const expenseChatData = ReportUtils . buildOptimisticChatReport ( {
79+ const expenseChatData = buildOptimisticChatReport ( {
8980 participantList : [ sessionAccountID ] ,
9081 reportName : '' ,
9182 chatType : CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ,
@@ -95,7 +86,7 @@ function addSchoolPrincipal(firstName: string, partnerUserID: string, lastName:
9586 oldPolicyName : policyName ,
9687 } ) ;
9788 const expenseChatReportID = expenseChatData . reportID ;
98- const expenseReportCreatedAction = ReportUtils . buildOptimisticCreatedReportAction ( sessionEmail ) ;
89+ const expenseReportCreatedAction = buildOptimisticCreatedReportAction ( sessionEmail ) ;
9990 const expenseReportActionData : ExpenseReportActionData = {
10091 [ expenseReportCreatedAction . reportActionID ] : expenseReportCreatedAction ,
10192 } ;
@@ -118,7 +109,7 @@ function addSchoolPrincipal(firstName: string, partnerUserID: string, lastName:
118109 owner : sessionEmail ,
119110 // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
120111 // eslint-disable-next-line deprecation/deprecation
121- outputCurrency : getPolicy ( policyID ) ?. outputCurrency ?? allPersonalDetails ?. [ sessionAccountID ] ?. localCurrencyCode ?? CONST . CURRENCY . USD ,
112+ outputCurrency : getPolicy ( policyID ) ?. outputCurrency ?? localCurrencyCode ?? CONST . CURRENCY . USD ,
122113 employeeList : {
123114 [ sessionEmail ] : {
124115 role : CONST . POLICY . ROLE . USER ,
0 commit comments