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

Flip TU constants for QA #31094

Merged
merged 14 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2881,8 +2881,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;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can create a hook to return the teachers' unite policyID and publicRoomID based on the environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This constants will be only used in these two places, so I think it's not necessary to move it to a hook atm

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() {
marcochavezf marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this condition to allow the teacher to enter again the principal email in case they entered the email incorrectly

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;
Loading