Skip to content

Commit

Permalink
Merge pull request #31094 from Expensify/marco-flipTUConstants
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl authored Jan 8, 2024
2 parents 102a2ab + 47e8c87 commit aed717d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2891,8 +2891,10 @@ const CONST = {
ATTACHMENT: 'common.attachment',
},
TEACHERS_UNITE: {
PUBLIC_ROOM_ID: '7470147100835202',
POLICY_ID: 'B795B6319125BDF2',
PROD_PUBLIC_ROOM_ID: '7470147100835202',
PROD_POLICY_ID: 'B795B6319125BDF2',
TEST_PUBLIC_ROOM_ID: '207591744844000',
TEST_POLICY_ID: 'ABD1345ED7293535',
POLICY_NAME: 'Expensify.org / Teachers Unite!',
PUBLIC_ROOM_NAME: '#teachers-unite',
},
Expand Down
19 changes: 11 additions & 8 deletions src/libs/actions/TeachersUnite.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,44 @@ Onyx.connect({
* @param {String} partnerUserID
* @param {String} firstName
* @param {String} lastName
* @param {String} policyID
* @param {String} publicRoomReportID - This is the global reportID for the public room, we'll ignore the optimistic one
*/
function referTeachersUniteVolunteer(partnerUserID, firstName, lastName) {
const optimisticPublicRoom = ReportUtils.buildOptimisticChatReport([], CONST.TEACHERS_UNITE.PUBLIC_ROOM_NAME, CONST.REPORT.CHAT_TYPE.POLICY_ROOM, CONST.TEACHERS_UNITE.POLICY_ID);
function referTeachersUniteVolunteer(partnerUserID, firstName, lastName, policyID, publicRoomReportID) {
const optimisticPublicRoom = ReportUtils.buildOptimisticChatReport([], CONST.TEACHERS_UNITE.PUBLIC_ROOM_NAME, CONST.REPORT.CHAT_TYPE.POLICY_ROOM, policyID);
const optimisticData = [
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticPublicRoom.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT}${publicRoomReportID}`,
value: {
...optimisticPublicRoom,
reportID: optimisticPublicRoom.reportID,
reportID: publicRoomReportID,
policyName: CONST.TEACHERS_UNITE.POLICY_NAME,
},
},
];
API.write(
'ReferTeachersUniteVolunteer',
{
publicRoomReportID: optimisticPublicRoom.reportID,
reportID: publicRoomReportID,
firstName,
lastName,
partnerUserID,
},
{optimisticData},
);
Navigation.dismissModal(CONST.TEACHERS_UNITE.PUBLIC_ROOM_ID);
Navigation.dismissModal(publicRoomReportID);
}

/**
* Optimistically creates a policyExpenseChat for the school principal and passes data to AddSchoolPrincipal
* @param {String} firstName
* @param {String} partnerUserID
* @param {String} lastName
* @param {String} policyID
*/
function addSchoolPrincipal(firstName, partnerUserID, lastName) {
function addSchoolPrincipal(firstName, partnerUserID, lastName, policyID) {
const policyName = CONST.TEACHERS_UNITE.POLICY_NAME;
const policyID = CONST.TEACHERS_UNITE.POLICY_ID;
const loggedInEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(sessionEmail);
const reportCreationData = {};

Expand All @@ -85,6 +87,7 @@ function addSchoolPrincipal(firstName, partnerUserID, lastName) {
firstName,
lastName,
partnerUserID,
policyID,
reportCreationData: JSON.stringify(reportCreationData),
},
{
Expand Down
5 changes: 4 additions & 1 deletion src/pages/TeachersUnite/IntroSchoolPrincipalPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
Expand All @@ -37,6 +38,7 @@ const defaultProps = {
function IntroSchoolPrincipalPage(props) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isProduction} = useEnvironment();

/**
* @param {Object} values
Expand All @@ -45,7 +47,8 @@ function IntroSchoolPrincipalPage(props) {
* @param {String} values.lastName
*/
const onSubmit = (values) => {
TeachersUnite.addSchoolPrincipal(values.firstName.trim(), values.partnerUserID.trim(), values.lastName.trim());
const policyID = isProduction ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID;
TeachersUnite.addSchoolPrincipal(values.firstName.trim(), values.partnerUserID.trim(), values.lastName.trim(), policyID);
};

/**
Expand Down
6 changes: 5 additions & 1 deletion src/pages/TeachersUnite/KnowATeacherPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
Expand All @@ -37,6 +38,7 @@ const defaultProps = {
function KnowATeacherPage(props) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isProduction} = useEnvironment();

/**
* Submit form to pass firstName, partnerUserID and lastName
Expand All @@ -52,7 +54,9 @@ function KnowATeacherPage(props) {
const firstName = values.firstName.trim();
const lastName = values.lastName.trim();

TeachersUnite.referTeachersUniteVolunteer(contactMethod, firstName, lastName);
const policyID = isProduction ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID;
const publicRoomReportID = isProduction ? CONST.TEACHERS_UNITE.PROD_PUBLIC_ROOM_ID : CONST.TEACHERS_UNITE.TEST_PUBLIC_ROOM_ID;
TeachersUnite.referTeachersUniteVolunteer(contactMethod, firstName, lastName, policyID, publicRoomReportID);
};

/**
Expand Down
41 changes: 7 additions & 34 deletions src/pages/TeachersUnite/SaveTheWorldPage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import _ from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import IllustratedHeaderPageLayout from '@components/IllustratedHeaderPageLayout';
import LottieAnimations from '@components/LottieAnimations';
import MenuItem from '@components/MenuItem';
Expand All @@ -11,28 +8,13 @@ import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

const propTypes = {
/** The list of this user's policies */
policy: PropTypes.shape({
/** The user's role in the policy */
role: PropTypes.string,
}),
};

const defaultProps = {
policy: {},
};

function SaveTheWorldPage(props) {
function SaveTheWorldPage() {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const isTeacherAlreadyInvited = !_.isUndefined(props.policy) && props.policy.role === CONST.POLICY.ROLE.USER;

return (
<IllustratedHeaderPageLayout
Expand All @@ -53,23 +35,14 @@ function SaveTheWorldPage(props) {
onPress={() => Navigation.navigate(ROUTES.I_KNOW_A_TEACHER)}
/>

{!isTeacherAlreadyInvited && (
<MenuItem
shouldShowRightIcon
title={translate('teachersUnitePage.iAmATeacher')}
onPress={() => Navigation.navigate(ROUTES.I_AM_A_TEACHER)}
/>
)}
<MenuItem
shouldShowRightIcon
title={translate('teachersUnitePage.iAmATeacher')}
onPress={() => Navigation.navigate(ROUTES.I_AM_A_TEACHER)}
/>
</IllustratedHeaderPageLayout>
);
}

SaveTheWorldPage.propTypes = propTypes;
SaveTheWorldPage.defaultProps = defaultProps;
SaveTheWorldPage.displayName = 'SaveTheWorldPage';

export default withOnyx({
policy: {
key: () => `${ONYXKEYS.COLLECTION.POLICY}${CONST.TEACHERS_UNITE.POLICY_ID}`,
},
})(SaveTheWorldPage);
export default SaveTheWorldPage;

0 comments on commit aed717d

Please sign in to comment.