-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
ref(forms): Migrate organization join request off deprecatedforms to scraps form #119194
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
Merged
priscilawebdev
merged 11 commits into
master
from
pri/ref-forms-migrate-organization-join-request
Jul 21, 2026
+118
−83
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0e4385e
ref(forms): Migrate organization join request off deprecatedforms to …
priscilawebdev 22d9359
ref(forms): Replace styled components with scraps primitives in join …
priscilawebdev 7e2c435
ref(forms): Add required indicator and use z.email validator
priscilawebdev 5469b72
test(forms): Add email validation test for join request form
priscilawebdev 4c8c63e
ref(forms): Keep submit button always enabled in join request form
priscilawebdev 917cbd7
ref(forms): Use Stack gap and mutation state in join request form
priscilawebdev 621ea23
ref(forms): Fix icon size, heading size, and footer spacing in join r…
priscilawebdev cd95ce0
ref(forms): Flatten nested Stack in join request form
priscilawebdev df55e34
ref(forms): Remove icon Container wrapper in join request success view
priscilawebdev 30d99d4
Merge branch 'master' into pri/ref-forms-migrate-organization-join-re…
priscilawebdev 67af526
Merge branch 'master' into pri/ref-forms-migrate-organization-join-re…
priscilawebdev 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 |
|---|---|---|
| @@ -1,113 +1,121 @@ | ||
| import {useCallback, useState} from 'react'; | ||
| import type {MouseEvent} from 'react'; | ||
| import styled from '@emotion/styled'; | ||
| import {useMutation} from '@tanstack/react-query'; | ||
| import {z} from 'zod'; | ||
|
|
||
| import {Button} from '@sentry/scraps/button'; | ||
| import {defaultFormOptions, useScrapsForm} from '@sentry/scraps/form'; | ||
| import {Container, Flex, Stack} from '@sentry/scraps/layout'; | ||
| import {Heading, Text} from '@sentry/scraps/text'; | ||
|
|
||
| import {addErrorMessage} from 'sentry/actionCreators/indicator'; | ||
| import {EmailField} from 'sentry/components/forms/fields/emailField'; | ||
| import {Form} from 'sentry/components/forms/form'; | ||
| import {NarrowLayout} from 'sentry/components/narrowLayout'; | ||
| import {IconMegaphone} from 'sentry/icons'; | ||
| import {t, tct} from 'sentry/locale'; | ||
| import {trackAnalytics} from 'sentry/utils/analytics'; | ||
| import {fetchMutation} from 'sentry/utils/queryClient'; | ||
| import {decodeScalar} from 'sentry/utils/queryString'; | ||
| import {testableWindowLocation} from 'sentry/utils/testableWindowLocation'; | ||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
| import {useParams} from 'sentry/utils/useParams'; | ||
|
|
||
| const joinRequestSchema = z.object({ | ||
| email: z.email(t('Please enter a valid email address')), | ||
| }); | ||
|
|
||
| export default function OrganizationJoinRequest() { | ||
| const {orgId} = useParams<{orgId: string}>(); | ||
| const location = useLocation(); | ||
| const [submitSuccess, setSubmitSuccess] = useState(false); | ||
|
|
||
| const handleSubmitSuccess = useCallback(() => { | ||
| setSubmitSuccess(true); | ||
| trackAnalytics('join_request.created', { | ||
| organization: orgId, | ||
| referrer: decodeScalar(location.query.referrer, ''), | ||
| }); | ||
| }, [orgId, location.query.referrer]); | ||
| const mutation = useMutation({ | ||
| mutationFn: (data: {email: string}) => | ||
| fetchMutation({ | ||
| url: `/organizations/${orgId}/join-request/`, | ||
| method: 'POST', | ||
| data, | ||
| }), | ||
| onSuccess: () => { | ||
| trackAnalytics('join_request.created', { | ||
| organization: orgId, | ||
| referrer: decodeScalar(location.query.referrer, ''), | ||
| }); | ||
| }, | ||
| onError: () => { | ||
| addErrorMessage(t('Request to join failed')); | ||
| }, | ||
| }); | ||
|
|
||
| const handleSubmitError = useCallback(() => { | ||
| addErrorMessage(t('Request to join failed')); | ||
| }, []); | ||
| const form = useScrapsForm({ | ||
| ...defaultFormOptions, | ||
| defaultValues: {email: ''}, | ||
| validators: {onDynamic: joinRequestSchema}, | ||
| onSubmit: ({value}) => mutation.mutateAsync(value).catch(() => {}), | ||
| }); | ||
|
|
||
| const handleCancel = useCallback( | ||
| (e: MouseEvent) => { | ||
| e.preventDefault(); | ||
| testableWindowLocation.assign(`/auth/login/${orgId}/`); | ||
| }, | ||
| [orgId] | ||
| ); | ||
| const handleCancel = (e: MouseEvent) => { | ||
| e.preventDefault(); | ||
| testableWindowLocation.assign(`/auth/login/${orgId}/`); | ||
| }; | ||
|
|
||
| if (submitSuccess) { | ||
| if (mutation.isSuccess) { | ||
| return ( | ||
| <NarrowLayout maxWidth="550px"> | ||
| <SuccessModal> | ||
| <StyledIconMegaphone size="2xl" /> | ||
| <StyledHeader>{t('Request Sent')}</StyledHeader> | ||
| <StyledText>{t('Your request to join has been sent.')}</StyledText> | ||
| <ReceiveEmailMessage> | ||
| {t('You will receive an email when your request is approved.')} | ||
| </ReceiveEmailMessage> | ||
| </SuccessModal> | ||
| <Stack align="center" gap="xl" paddingTop="lg" paddingBottom="3xl"> | ||
| <IconMegaphone size="xl" /> | ||
| <Stack align="center" gap="md"> | ||
| <Heading as="h3" size="xl"> | ||
| {t('Request Sent')} | ||
| </Heading> | ||
| <Text as="p" align="center"> | ||
| {t('Your request to join has been sent.')} | ||
| </Text> | ||
| <Container maxWidth="250px"> | ||
| <Text as="p" align="center"> | ||
| {t('You will receive an email when your request is approved.')} | ||
| </Text> | ||
| </Container> | ||
| </Stack> | ||
| </Stack> | ||
| </NarrowLayout> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <NarrowLayout maxWidth="650px"> | ||
| <StyledIconMegaphone size="2xl" /> | ||
| <StyledHeader data-test-id="join-request">{t('Request to Join')}</StyledHeader> | ||
| <StyledText> | ||
| {tct('Ask the admins if you can join the [orgId] organization.', { | ||
| orgId, | ||
| })} | ||
| </StyledText> | ||
| <Form | ||
| requireChanges | ||
| apiEndpoint={`/organizations/${orgId}/join-request/`} | ||
| apiMethod="POST" | ||
| submitLabel={t('Request to Join')} | ||
| onSubmitSuccess={handleSubmitSuccess} | ||
| onSubmitError={handleSubmitError} | ||
| onCancel={handleCancel} | ||
| > | ||
| <StyledEmailField | ||
| name="email" | ||
| inline={false} | ||
| label={t('Email Address')} | ||
| placeholder="name@example.com" | ||
| /> | ||
| </Form> | ||
| <Stack gap="xl"> | ||
| <IconMegaphone size="xl" /> | ||
| <Stack gap="md"> | ||
| <Heading as="h3" size="xl" data-test-id="join-request"> | ||
| {t('Request to Join')} | ||
| </Heading> | ||
| <Text as="p"> | ||
| {tct('Ask the admins if you can join the [orgId] organization.', { | ||
| orgId, | ||
| })} | ||
| </Text> | ||
| </Stack> | ||
| <form.AppForm form={form}> | ||
| <Stack gap="xl"> | ||
| <form.AppField name="email"> | ||
| {field => ( | ||
| <field.Layout.Stack label={t('Email Address')} required> | ||
| <field.Input | ||
| type="email" | ||
| value={field.state.value} | ||
| onChange={field.handleChange} | ||
| placeholder="name@example.com" | ||
| /> | ||
| </field.Layout.Stack> | ||
| )} | ||
| </form.AppField> | ||
| <Container borderTop="secondary" paddingTop="xl" paddingBottom="xl"> | ||
| <Flex gap="md" justify="end"> | ||
| <Button onClick={handleCancel}>{t('Cancel')}</Button> | ||
| <form.SubmitButton>{t('Request to Join')}</form.SubmitButton> | ||
| </Flex> | ||
| </Container> | ||
| </Stack> | ||
| </form.AppForm> | ||
| </Stack> | ||
| </NarrowLayout> | ||
| ); | ||
| } | ||
|
|
||
| const SuccessModal = styled('div')` | ||
| display: grid; | ||
| justify-items: center; | ||
| text-align: center; | ||
| padding-top: 10px; | ||
| padding-bottom: ${p => p.theme.space['3xl']}; | ||
| `; | ||
|
|
||
| const StyledIconMegaphone = styled(IconMegaphone)` | ||
| padding-bottom: ${p => p.theme.space['2xl']}; | ||
| `; | ||
|
|
||
| const StyledHeader = styled('h3')` | ||
| margin-bottom: ${p => p.theme.space.md}; | ||
| `; | ||
|
|
||
| const StyledText = styled('p')` | ||
| margin-bottom: 0; | ||
| `; | ||
|
|
||
| const ReceiveEmailMessage = styled(StyledText)` | ||
| max-width: 250px; | ||
| `; | ||
|
|
||
| const StyledEmailField = styled(EmailField)` | ||
| padding-top: ${p => p.theme.space.xl}; | ||
| padding-left: 0; | ||
| `; | ||
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.
Bug: The
trackAnalyticscall forjoin_request.createdsends anorganizationproperty, which mismatches the backend's expectedorganization_idand the frontend's TypeScript definition.Severity: LOW
Suggested Fix
Update the
trackAnalyticscall to send the correct properties as expected by the backend. This involves changingorganization: orgIdtoorganization_id: parseInt(orgId, 10)and adding the requiredmember_id. Also, update the frontend TypeScript definition for the event to match the new payload structure to resolve the type error.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.