-
-
Notifications
You must be signed in to change notification settings - Fork 168
Legislator Profile Type #2166
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
Open
ACoullard
wants to merge
7
commits into
codeforboston:main
Choose a base branch
from
ACoullard:AC/legislator-accounts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Legislator Profile Type #2166
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2944cc2
backend changes
ACoullard 4195aef
frontend changes
ACoullard 36985f8
prettier and type fix
ACoullard 3a70458
update ui
ACoullard cfb03ca
prettier
ACoullard f35f619
update svgs
ACoullard 67e6a3b
fix for mobile
ACoullard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { MessageBanner } from "./shared/MessageBanner" | ||
| import { useTranslation } from "next-i18next" | ||
|
|
||
| export const PendingLegislatorBanner = () => { | ||
| const { t } = useTranslation("common") | ||
| return ( | ||
| <MessageBanner | ||
| icon={"/Clock.svg"} | ||
| heading={t("pending_legislator_warning.header")} | ||
| content={t("pending_legislator_warning.content")} | ||
| /> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { mapleClient } from "./maple-client" | ||
|
|
||
| /** | ||
| * Changes the user's role to "legislator", approving their legislator account request. | ||
| * | ||
| * Requires the logged-in user to be an admin. | ||
| */ | ||
| export async function acceptLegislatorRequest(userId: string) { | ||
| return mapleClient.patch(`/api/users/${userId}`, { role: "legislator" }) | ||
| } | ||
|
|
||
| /** | ||
| * Rejects a pending legislator request by reverting the user's role to "user". | ||
| * Also releases the claimed member code so it can be claimed by others. | ||
| * | ||
| * Requires the logged-in user to be an admin. | ||
| */ | ||
| export async function rejectLegislatorRequest(userId: string) { | ||
| return mapleClient.patch(`/api/users/${userId}`, { role: "user" }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| import { useEffect, useMemo, useState } from "react" | ||
| import clsx from "clsx" | ||
| import type { ModalProps } from "react-bootstrap" | ||
| import { useForm } from "react-hook-form" | ||
| import { Alert, Button, Col, Form, Modal, Row, Stack } from "../bootstrap" | ||
| import { LoadingButton } from "../buttons" | ||
| import Input from "../forms/Input" | ||
| import PasswordInput from "../forms/PasswordInput" | ||
| import { | ||
| CreateLegislatorWithEmailAndPasswordData, | ||
| useCreateLegislatorWithEmailAndPassword | ||
| } from "./hooks" | ||
| import TermsOfServiceModal from "./TermsOfServiceModal" | ||
| import { useTranslation } from "next-i18next" | ||
| import { Search } from "../legislatorSearch" | ||
| import { useClaimedMemberCodes, useMemberSearch } from "../db/members" | ||
| import { ProfileMember } from "../db" | ||
|
|
||
| export default function LegislatorSignUpModal({ | ||
| show, | ||
| onHide, | ||
| onSuccessfulSubmit | ||
| }: Pick<ModalProps, "show" | "onHide"> & { | ||
| onSuccessfulSubmit: () => void | ||
| onHide: () => void | ||
| }) { | ||
| const { | ||
| register, | ||
| handleSubmit, | ||
| reset, | ||
| getValues, | ||
| trigger, | ||
| formState: { errors } | ||
| } = useForm<CreateLegislatorWithEmailAndPasswordData>() | ||
|
|
||
| const [tosStep, setTosStep] = useState<"not-agreed" | "reading" | "agreed">( | ||
| "not-agreed" | ||
| ) | ||
| const [selectedMember, setSelectedMember] = useState<ProfileMember | null>( | ||
| null | ||
| ) | ||
| const [memberError, setMemberError] = useState<string | undefined>() | ||
|
|
||
| const showTos = tosStep === "reading" | ||
|
|
||
| const createLegislatorWithEmailAndPassword = | ||
| useCreateLegislatorWithEmailAndPassword() | ||
|
|
||
| const { index } = useMemberSearch() | ||
| const { claimedCodes } = useClaimedMemberCodes() | ||
|
|
||
| const memberIndex = useMemo(() => { | ||
| const all = [...(index?.representatives ?? []), ...(index?.senators ?? [])] | ||
| if (!claimedCodes) return all | ||
| return all.filter(m => !claimedCodes.has(m.MemberCode)) | ||
| }, [index, claimedCodes]) | ||
|
|
||
| const { t } = useTranslation("auth") | ||
|
|
||
| useEffect(() => { | ||
| if (!show) { | ||
| reset() | ||
| setTosStep("not-agreed") | ||
| setSelectedMember(null) | ||
| setMemberError(undefined) | ||
| createLegislatorWithEmailAndPassword.reset() | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [show, reset]) | ||
|
|
||
| const onSubmit = handleSubmit(newUser => { | ||
| if (!selectedMember) { | ||
| setMemberError( | ||
| t("legislatorRequired") ?? "Please select your legislator profile." | ||
| ) | ||
| return | ||
| } | ||
| setMemberError(undefined) | ||
| const promise = createLegislatorWithEmailAndPassword.execute({ | ||
| ...newUser, | ||
| memberCode: selectedMember.id | ||
| }) | ||
| promise.then(onSuccessfulSubmit).catch(() => {}) | ||
| }) | ||
|
|
||
| async function handleContinueClick() { | ||
| if (!selectedMember) { | ||
| setMemberError( | ||
| t("legislatorRequired") ?? "Please select your legislator profile." | ||
| ) | ||
| return | ||
| } | ||
| setMemberError(undefined) | ||
| const isValid = await trigger() | ||
| if (isValid) { | ||
| setTosStep("reading") | ||
| } | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| if (tosStep === "agreed") { | ||
| const loadingbtn = document.getElementById("legislator-loading-button") | ||
| loadingbtn?.click() | ||
| } | ||
| }, [tosStep]) | ||
|
|
||
| return ( | ||
| <> | ||
| <Modal | ||
| show={show} | ||
| onHide={onHide} | ||
| aria-labelledby="legislator-sign-up-modal" | ||
| centered | ||
| size="lg" | ||
| className={clsx(showTos && "opacity-0")} | ||
| > | ||
| <Modal.Header closeButton> | ||
| <Modal.Title id="legislator-sign-up-modal"> | ||
| {t("signUpAsLegislator") ?? "Sign Up as Legislator"} | ||
| </Modal.Title> | ||
| </Modal.Header> | ||
| <Modal.Body> | ||
| <Col md={12} className="mx-auto"> | ||
| {createLegislatorWithEmailAndPassword.error ? ( | ||
| <Alert variant="danger"> | ||
| {createLegislatorWithEmailAndPassword.error.message} | ||
| </Alert> | ||
| ) : null} | ||
|
|
||
| <Form noValidate onSubmit={onSubmit}> | ||
| <TermsOfServiceModal | ||
| show={showTos} | ||
| onHide={() => setTosStep("not-agreed")} | ||
| onAgree={() => setTosStep("agreed")} | ||
| /> | ||
|
|
||
| <Stack gap={3} className="mb-4"> | ||
| <Input | ||
| label={t("email") ?? "Email"} | ||
| type="email" | ||
| {...register("email", { | ||
| required: t("emailIsRequired") ?? "An email is required." | ||
| })} | ||
| error={errors.email?.message} | ||
| /> | ||
|
|
||
| <Input | ||
| label={t("fullName") ?? "Full Name"} | ||
| type="text" | ||
| {...register("fullName", { | ||
| validate: value => | ||
| value.trim().length >= 2 || | ||
| t("errEmptyAndMinLength").toString(), | ||
| required: t("nameIsRequired") ?? "A full name is required." | ||
| })} | ||
| error={errors.fullName?.message} | ||
| /> | ||
|
|
||
| <Form.Group controlId="legislatorSearch"> | ||
| <Form.Label>{t("selectLegislatorHeader")}</Form.Label> | ||
| <Search | ||
| index={memberIndex} | ||
| update={member => { | ||
| setSelectedMember(member) | ||
| if (member) setMemberError(undefined) | ||
| }} | ||
| memberId={selectedMember?.id} | ||
| placeholder={t("searchLegislatorsPlaceholder")} | ||
| menuPortalTarget={document.body} | ||
| styles={{ | ||
| menuPortal: (base: any) => ({ ...base, zIndex: 9999 }) | ||
| }} | ||
| /> | ||
| {memberError && ( | ||
| <Form.Text className="text-danger">{memberError}</Form.Text> | ||
| )} | ||
| </Form.Group> | ||
|
|
||
| <Row className="g-3"> | ||
| <Col md={6}> | ||
| <PasswordInput | ||
| label={t("password") ?? "Password"} | ||
| {...register("password", { | ||
| required: | ||
| t("passwordRequired") ?? "A password is required.", | ||
| minLength: { | ||
| value: 8, | ||
| message: | ||
| t("passwordLength") ?? | ||
| "Your password must be 8 characters or longer." | ||
| }, | ||
| deps: ["confirmedPassword"] | ||
| })} | ||
| error={errors.password?.message} | ||
| /> | ||
| </Col> | ||
|
|
||
| <Col md={6}> | ||
| <PasswordInput | ||
| label={t("confirmPassword") ?? "Confirm Password"} | ||
| {...register("confirmedPassword", { | ||
| required: | ||
| t("mustConfirmPassword") ?? | ||
| "You must confirm your password.", | ||
| validate: confirmedPassword => { | ||
| const password = getValues("password") | ||
| return confirmedPassword !== password | ||
| ? t("mustMatch") ?? | ||
| "Confirmed password must match password." | ||
| : undefined | ||
| } | ||
| })} | ||
| error={errors.confirmedPassword?.message} | ||
| /> | ||
| </Col> | ||
| </Row> | ||
| </Stack> | ||
| {tosStep === "agreed" ? ( | ||
| <LoadingButton | ||
| id="legislator-loading-button" | ||
| type="submit" | ||
| className="w-100" | ||
| loading={createLegislatorWithEmailAndPassword.loading} | ||
| > | ||
| {t("signUp") ?? "Sign Up"} | ||
| </LoadingButton> | ||
| ) : ( | ||
| <Button | ||
| className="w-100" | ||
| type="button" | ||
| onClick={handleContinueClick} | ||
| > | ||
| {t("continue") ?? "Continue"} | ||
| </Button> | ||
| )} | ||
| </Form> | ||
| </Col> | ||
| </Modal.Body> | ||
| </Modal> | ||
| </> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the thought you put into the user experience here, but I think we can get away without excluding already claimed member codes. Any legitimate legislator will only try to claim themselves (and we have a search input to help them find themselves) and any illegitimate user doesn't deserve a good user experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think it may be more helpful in the admin view than the user-facing view.
It's possible more than one person will submit a request for a given legislator (possibly, but not necessarily maliciously - it could be the legislator and a staffer requesting from different email addresses). In that case, I think it's fine to let the users submit what they want and let the admins sort out the real deal.
(It's also possible the real legislator tries to claim the account second - so it may be desirable to leave their name in the select box so they can more easily contest ownership)
If so, we do want the MAPLE admin to know if there are multiple requests for a given member (even if one request has been previously accepted) - we should expose that in the admin interface for additional context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does raise an issue about user verification I'd love to discuss:
Rebecca Rauschlegislator profile with her statehouse email, a MAPLE admin sees the request and approves it, and then I can post anything I want as Rebecca Rausch)email_verified: falsefrom the admin viewThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a nice-to-have (that may or may not make things easier in this PR, so I'll bring it up anyway):
my_legislator@ma.senate.gov) and we could even auto-approve requests to claim a legislator from a verified government email address (to cut down on the worklog for our admins)@mvictor55 How do you plan to approve/reject legislator profile requests? Do we need them to sign up with their government email so we have some proof they're real, or are there other signals we should look/ask for? We should discuss this at hack night.