Skip to content

Commit

Permalink
Merge pull request #186 from m2mathew/fix/send_correct_auth_user_id_t…
Browse files Browse the repository at this point in the history
…o_firestore

Fix/send correct auth user id to firestore
  • Loading branch information
m2mathew authored Aug 2, 2023
2 parents 22c597a + e7c98b4 commit 2f5ca7a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tmac-website",
"description": "Website for the Texas Music Administrators Conference",
"version": "2.30.2",
"version": "2.30.3",
"repository": {
"type": "git",
"url": "https://github.com/m2mathew/tmac-website"
Expand Down
11 changes: 9 additions & 2 deletions src/components/members/MemberContent/MemberInfo/MemberStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import MemberInfoCard from '../../../shared/MemberInfoCard';
import PaypalButtonWrapper from '../../../register/paypal/paypal-button-wrapper';
import PrintInvoiceUI from '../../../../pages/members/PrintInvoiceUI';
import { appNameShort } from '../../../../utils/app-constants';
import { TfaaAuthUser } from '../../../layout';

// Local Typings
interface Props {
currentAuthUser: TfaaAuthUser | null;
currentMemberData: TfaaMemberData | null;
}

Expand Down Expand Up @@ -103,7 +105,10 @@ const StyledStrong = styled.strong(({ theme }) => ({
}));

// Component Definition
const MemberStatus: React.FC<Props> = ({ currentMemberData }) => {
const MemberStatus: React.FC<Props> = ({
currentAuthUser,
currentMemberData,
}) => {
const isRegisteredForCurrentYear = Boolean(currentMemberData);

// If the member paid by check, the TFAA Executive Secretary will manually
Expand All @@ -128,14 +133,16 @@ const MemberStatus: React.FC<Props> = ({ currentMemberData }) => {
receiptId: currentMemberData?.receiptId ?? 0,
};

const userId = `${currentAuthUser?.email}-${currentAuthUser?.uid}`;

// Update the member's payment data in the Firestore database
// This shape should be the same as register-membmer-payment
// in the handleCompleteMemberPaymentStep function
try {
await doUpdateEntry(
updatedMemberData,
FIRESTORE_MEMBER_COLLECTION,
currentMemberData?.userId,
userId,
);
} catch (error) {
console.error('Error while updating after a successful payment', error);
Expand Down
8 changes: 7 additions & 1 deletion src/components/members/MemberContent/MemberInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import MemberContactInfo from './MemberContactInfo';
import MemberRegistrationTasks from './MemberRegistrationTasks';
import MemberStatus from './MemberStatus';
import AdminActions from './AdminActions';
import { TfaaAuthUser } from '../../../layout';

// Local Typings
interface Props {
authUserEmail: string | undefined;
currentAuthUser: TfaaAuthUser | null;
currentMemberData: TfaaMemberData | null;
isAdmin: boolean;
onUpdateShouldRefetchUserList: ((shouldRefetchUserList: boolean) => void) | null;
Expand Down Expand Up @@ -60,6 +62,7 @@ const StyledRoot = styled.div(({ theme }) => ({
// Component Definition
const MemberInfo: React.FC<Props> = ({
authUserEmail,
currentAuthUser,
currentMemberData,
onUpdateShouldRefetchUserList,
}) => {
Expand All @@ -71,7 +74,10 @@ const MemberInfo: React.FC<Props> = ({
<StyledRoot>
<Motifs small />

<MemberStatus currentMemberData={currentMemberData} />
<MemberStatus
currentAuthUser={currentAuthUser}
currentMemberData={currentMemberData}
/>

{currentMemberData && (
<MemberContactInfo
Expand Down
8 changes: 4 additions & 4 deletions src/components/members/MemberContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ const MemberContent: React.FC<Props> = ({ currentAuthUser }) => {
useEffect(() => {
if (currentAuthUser && allMembersData && allMembersData.length > 0 && !currentMemberData) {
const currentMember = allMembersData.find(
// We used to use authUser.uid as the unique key in the Firestore
// Now we use authUser.email
// We have to search for both for backwards compatibility
// We use a combination of email and uid to uniquely identify a user.
// The email part makes it easier to find a user in the database.
(user) => {
return user.userId === currentAuthUser.uid || user.userId === currentAuthUser.email;
return user.userId === `${currentAuthUser.email}-${currentAuthUser.uid}`;
});

setCurrentMemberData(currentMember ?? null);
Expand All @@ -65,6 +64,7 @@ const MemberContent: React.FC<Props> = ({ currentAuthUser }) => {

<MemberInfo
authUserEmail={currentAuthUser?.email || currentMemberData?.Email}
currentAuthUser={currentAuthUser}
currentMemberData={currentMemberData}
isAdmin={isAdmin}
onUpdateShouldRefetchUserList={handleUpdateShouldRefetchUserList}
Expand Down
6 changes: 4 additions & 2 deletions src/components/register/SponsorRegisterContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ const SponsorRegisterContent: React.FC = () => {

const hasCompletedAllSponsorSteps = completedSponsorSteps?.length >= 3;

const authenticatedUserId = `${currentAuthUser?.email}-${currentAuthUser?.uid}`;

/* Children change depending on which step is active */
return (
<StyledRoot>
Expand All @@ -237,7 +239,7 @@ const SponsorRegisterContent: React.FC = () => {
)}
{activeStep === 1 && (
<RegisterSponsorFormWrapper
authenticatedUserId={`${currentAuthUser?.email}-${currentAuthUser?.uid}`}
authenticatedUserId={authenticatedUserId}
initialSponsorFormValues={INITIAL_SPONSOR_FORM_VALUES}
onCompleteSponsorStep={handleCompleteSponsorStep}
onUpdateSponsorForm={handleUpdateSponsorForm}
Expand All @@ -246,7 +248,7 @@ const SponsorRegisterContent: React.FC = () => {
)}
{[2, 3].includes(activeStep) && (
<RegisterSponsorPayment
authenticatedUserId={currentAuthUser?.uid}
authenticatedUserId={authenticatedUserId}
onUpdateSponsorForm={handleUpdateSponsorForm}
sponsorForm={sponsorForm}
/>
Expand Down

0 comments on commit 2f5ca7a

Please sign in to comment.