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

Mail to legislators and show stored testimony into EditTestimony modal #281

Merged
merged 21 commits into from
Mar 9, 2022

Conversation

jkoren
Copy link
Collaborator

@jkoren jkoren commented Mar 7, 2022

No description provided.

@github-actions
Copy link

github-actions bot commented Mar 7, 2022

Visit the preview URL for this PR (updated for commit jkoren/advocacy-maps@c21ad30):

https://digital-testimony-dev--pr281-mail-to-legislators-qoxqzt34.web.app

(expires Wed, 16 Mar 2022 16:49:58 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bc0858669d4997df2a9165c2144bd1e2dbba0242

@jkoren jkoren linked an issue Mar 8, 2022 that may be closed by this pull request
Copy link
Member

@alexjball alexjball left a comment

Choose a reason for hiding this comment

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

Awesome work, Jeff! I'm excited to see this coming together.

Could you also update ExpandTestimony.js to show the whitespace in the testimony?

          <p style={{whiteSpace: "pre-wrap"}}>{testimony ? testimony.content : ""}</p>

Comment on lines 33 to 34
const senatorEmail = senatorId ? GetMemberEmail(senatorId) : ""
const representativeEmail = representativeId ? GetMemberEmail(representativeId) : ""
Copy link
Member

Choose a reason for hiding this comment

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

If I have legislators selected, these lines cause an error. One of the rules of hooks is not to call hooks conditionally. Since GetMemberEmail calls useMembers, we're violating that rule. things seem to work with these lines:

    const senator = useMember(profile?.senator?.id)
    const senatorEmail = senator.member?.EmailAddress ?? ""
    const representative = useMember(profile?.representative?.id)
    const representativeEmail = representative.member?.EmailAddress ?? ""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice! I updated the code.

const edit = useEditTestimony(user.uid, bill.BillNumber)
const positionMessage = "Select my support..(required)"

const url = `mailto:${senatorEmail},${representativeEmail}?subject=My testimony on Bill ${bill ? bill.BillNumber : ""}&body=${testimony ? testimony.content : ""}`
Copy link
Member

Choose a reason for hiding this comment

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

We should wrap this url in encodeURI. Some characters like newlines and spaces aren't allowed in URL's. This converts them to escape strings like %20 so they show up correctly in the email draft

    const url = encodeURI(`mailto:${senatorEmail},${representativeEmail}?subject=My testimony on Bill ${bill ? bill.BillNumber : ""}&body=${testimony ? testimony.content : ""}`)


const publishTestimony = async () => {
if (testimony.position == undefined || testimony.position == positionMessage) { return }
handleCloseTestimony()
Copy link
Member

Choose a reason for hiding this comment

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

let's move this down two lines, so the modal closes after the testimony is published.

Also, what do you think about adding a loading state to the publish button? we can have an isPublishing useState value that we set to true before saving the draft and false after publishing testimony. Then if isPublishing is true, we disable the publish button and change the text to "Loading..."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like it!

Comment on lines 82 to 91
<div>
<links.External href={url}>
Send copy to your legislators
</links.External>
</div>
<div>
<links.External href={url}>
Send copy to relevant committee
</links.External>
</div>
Copy link
Member

Choose a reason for hiding this comment

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

Should we show these if the user has not chosen legislators? Maybe a note to say "add your legislators in your profile to email them your testimony"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like it

const defaultContent = testimony && testimony.content ? testimony.content : defaultTestimony

const publishTestimony = async () => {
if (testimony.position == undefined || testimony.position == positionMessage) { return }
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a validation error message to the form in this case so the user can more easily tell why the form didn't submit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. I changed the publish button to be "Select your support to publish" if they haven't chosen a position to explain why it doesn't submit.
image

@alexjball
Copy link
Member

One of the integration tests is changing due to the changes in useEditTestimony. We can disable this test for now by adding .skip:

  it.skip("Does nothing on publish if draft is up to date", async () => {

}

const positionChosen = testimony.position != undefined && testimony.position != positionMessage
Copy link
Member

Choose a reason for hiding this comment

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

I think the second condition should be testimony.content !== positionMessage

Copy link
Collaborator Author

@jkoren jkoren Mar 9, 2022

Choose a reason for hiding this comment

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

actually the original is correct. it is testing to make sure that the user has not re-chosen the default position, which is "Select my support..(required)" This would only happen if the user chooses a position such as "Endorse" and then re-selects the "Select my support..(required)" option.
I tried to disable the "Select my support..(required)" option, but then the menu defaults to this first enabled option "Endorse"

Copy link
Member

@alexjball alexjball left a comment

Choose a reason for hiding this comment

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

🥳

@jkoren jkoren merged commit f133544 into codeforboston:master Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment