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

✨ Added PollResponse Through Email #108

Merged
merged 1 commit into from
Mar 17, 2021
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: 5 additions & 1 deletion src/components/poll/PollTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ const PollTable = (props: {
</tbody>
</Table>
{pollFromDB.open && loggedInUserEmailID !== pollCreatorEmailID && (
<SubmitChoices newVote={newVote} pollID={pollID} />
<SubmitChoices
newVote={newVote}
pollID={pollID}
pollFromDB={pollFromDB}
/>
)}
{pollFromDB.open && loggedInUserEmailID === pollCreatorEmailID && (
<SubmitFinalChoice finalChoice={finalChoice} pollID={pollID} />
Expand Down
27 changes: 25 additions & 2 deletions src/components/poll/SubmitChoices.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { Button, Spinner } from "react-bootstrap";
import { useState } from "react";
import Router from "next/router";
import { useSelector } from "react-redux";
import { markChoices } from "../../utils/api/server";
import { Vote } from "../../models/poll";
import { Vote, RocketMeetPollFromDB, MailerArgs } from "../../models/poll";
import ResponseMessage from "../ResponseMessage";
import { decrypt } from "../../helpers/helpers";
import { sendPollResponse } from "../../utils/api/mailer";
import { RootState } from "../../store/store";

const SubmitChoices = (props: {
newVote: Vote;
pollID: string;
pollFromDB: RocketMeetPollFromDB;
}): JSX.Element => {
const { newVote, pollID } = props;
const { newVote, pollID, pollFromDB } = props;
const pollCreatorEmailID = decrypt(pollFromDB.encryptedEmailID);
const token = useSelector((state: RootState) => state.authReducer.token);
const isLoggedIn = useSelector(
(state: RootState) => state.authReducer.isLoggedIn
);
const senderEmailID = useSelector(
(state: RootState) => state.authReducer.username
);

const [response, setResponse] = useState({
status: false,
Expand All @@ -31,6 +44,16 @@ const SubmitChoices = (props: {
};
const submitChoiceResponse = await markChoices(voterArgs);
if (submitChoiceResponse.statusCode === 201) {
if (isLoggedIn) {
const mailerArgs: MailerArgs = {
pollID,
senderEmailID,
pollTitle: pollFromDB.title,
receiverIDs: Array<string>(pollCreatorEmailID),
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
senderName: newVote.name,
};
sendPollResponse(mailerArgs, token);
anandbaburajan marked this conversation as resolved.
Show resolved Hide resolved
}
Router.reload();
Copy link
Contributor Author

@PushkarDureja PushkarDureja Mar 21, 2021

Choose a reason for hiding this comment

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

After commenting line 57 I took a screenshot of network logs and It shows the pollresponse request is working fine
image

} else if (submitChoiceResponse.statusCode === 400) {
setResponse({
Expand Down
12 changes: 11 additions & 1 deletion src/utils/api/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ const sendFinalTime = (
return httpPost(payload, endpoint, token);
};

export { sendPollInvites, sendFinalTime };
const sendPollResponse = (
// Send poll creater an email, everytime someone votes on their poll
mailerArgs: MailerArgs,
token: string
): Promise<MailerResponse> => {
const payload = JSON.stringify(mailerArgs);
const endpoint = `${URL}/pollResponse`;
return httpPost(payload, endpoint, token);
};

export { sendPollInvites, sendFinalTime, sendPollResponse };