diff --git a/messages/en.json b/messages/en.json index d6ff8cbf..6335d31b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -1,7 +1,8 @@ { "common": { - "sealFeedbackButtonLabel": "Got feedback?", + "feedbackButtonLabel": "Got feedback?", "sealFeedbackButtonAriaLabel": "Share feedback on the Seal of Reliability (opens in a new tab)", + "notificationsFeedbackButtonAriaLabel": "Share feedback on notifications (opens in a new tab)", "copyToClipboard": "Copy to clipboard", "copied": "Copied!", "name": "Name", diff --git a/messages/fr.json b/messages/fr.json index 411d8ce8..817d3d8a 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -1,7 +1,8 @@ { "common": { - "sealFeedbackButtonLabel": "Des commentaires ?", + "feedbackButtonLabel": "Des commentaires ?", "sealFeedbackButtonAriaLabel": "Donnez votre avis sur le Sceau de fiabilité (ouvre un nouvel onglet)", + "notificationsFeedbackButtonAriaLabel": "Donnez votre avis sur les notifications (ouvre un nouvel onglet)", "copyToClipboard": "Copier dans le presse-papiers", "copied": "Copié!", "name": "Nom", diff --git a/src/app/[locale]/account/notifications/AccountNotifications.tsx b/src/app/[locale]/account/notifications/AccountNotifications.tsx index 1af77f64..f9c54aa4 100644 --- a/src/app/[locale]/account/notifications/AccountNotifications.tsx +++ b/src/app/[locale]/account/notifications/AccountNotifications.tsx @@ -22,6 +22,8 @@ import Typography from '@mui/material/Typography'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import { Link as LocaleLink } from '../../../../i18n/navigation'; import { useAuthSession } from '../../../components/AuthSessionProvider'; +import FeedbackButton from '../../../components/FeedbackButton'; +import { useUserFeatureFlags } from '../../../hooks/useUserFeatureFlags'; import NotificationSettingsDialog, { type NotificationSettings, } from '../../../screens/Feed/components/NotificationSettingsDialog'; @@ -50,6 +52,12 @@ type SortKey = 'title' | 'type' | 'status'; export default function AccountNotifications(): React.ReactElement { const t = useTranslations('feeds'); const { isAuthenticated } = useAuthSession(); + const { flags: userFeatureFlags, isResolved: areUserFeatureFlagsResolved } = + useUserFeatureFlags(); + // The feedback form is for users in the notifications early release, so the + // button stays hidden until their entitlement is known and true. + const showFeedbackButton = + areUserFeatureFlagsResolved && userFeatureFlags.isNotificationsEnabled; const [orderBy, setOrderBy] = React.useState(null); const [order, setOrder] = React.useState<'asc' | 'desc'>('asc'); @@ -276,6 +284,7 @@ export default function AccountNotifications(): React.ReactElement { subtitle='View and manage the feeds you are subscribed to for update notifications' loading={isLoading} > + {showFeedbackButton && } - + { return ( - + ; /** + * + * Floating "Got feedback?" link to a feature's Google Form: a vertical tab on + * the right edge on large screens, a FAB in the bottom-right corner below. * * The user's name and email are prefilled into the form when the app knows * them. Both sources are read because they settle at different times: the @@ -23,7 +34,9 @@ import { * an unprefilled form - the link is never gated on identity. * */ -export default function SealFeedbackButton(): ReactElement { +export default function FeedbackButton({ + form, +}: FeedbackButtonProps): ReactElement { const t = useTranslations('common'); const user = useAppSelector(selectUserProfile); const { @@ -52,8 +65,10 @@ export default function SealFeedbackButton(): ReactElement { // prefill, so it works for anyone who clicks during hydration. const feedbackUrl = useMemo( () => - isMounted ? buildSealFeedbackUrl({ name, email }) : SEAL_FEEDBACK_URL, - [isMounted, name, email], + isMounted + ? buildFeedbackUrl(form, { name, email }) + : buildFeedbackUrl(form), + [form, isMounted, name, email], ); return ( @@ -64,8 +79,8 @@ export default function SealFeedbackButton(): ReactElement { href={feedbackUrl} target='_blank' rel='noreferrer' - data-testid='seal-feedback-button' - aria-label={t('sealFeedbackButtonAriaLabel')} + data-testid={`${form}-feedback-button`} + aria-label={t(ARIA_LABEL_KEYS[form])} sx={{ display: { xs: 'none', lg: 'inline-flex' }, position: 'fixed', @@ -80,15 +95,15 @@ export default function SealFeedbackButton(): ReactElement { }} startIcon={} > - {t('sealFeedbackButtonLabel')} + {t('feedbackButtonLabel')} - + diff --git a/src/app/utils/seal-feedback-url.spec.ts b/src/app/utils/feedback-url.spec.ts similarity index 54% rename from src/app/utils/seal-feedback-url.spec.ts rename to src/app/utils/feedback-url.spec.ts index be2737c0..08398930 100644 --- a/src/app/utils/seal-feedback-url.spec.ts +++ b/src/app/utils/feedback-url.spec.ts @@ -1,47 +1,57 @@ -import { buildSealFeedbackUrl, SEAL_FEEDBACK_URL } from './seal-feedback-url'; +import { buildFeedbackUrl, FEEDBACK_FORMS } from './feedback-url'; -describe('buildSealFeedbackUrl', () => { +describe('buildFeedbackUrl', () => { it('returns the bare form URL when nothing is known about the user', () => { - const url = buildSealFeedbackUrl(); + const url = buildFeedbackUrl('seal'); - expect(url).toBe('https://share.mobilitydata.org/sealfeedback'); + expect(url).toContain('/viewform'); expect(url).not.toContain('usp=pp_url'); expect(url).not.toContain('entry.'); }); - it('exposes the same bare URL the server renders before hydration', () => { - expect(SEAL_FEEDBACK_URL).toBe(buildSealFeedbackUrl()); + it.each(Object.keys(FEEDBACK_FORMS) as Array)( + 'points the %s form at its own unprefilled URL', + (form) => { + expect(buildFeedbackUrl(form)).toBe(FEEDBACK_FORMS[form]); + }, + ); + + it('keeps the seal and notifications forms distinct', () => { + expect(buildFeedbackUrl('seal')).not.toBe( + buildFeedbackUrl('notifications'), + ); }); it('prefills both name and email when both are available', () => { const url = new URL( - buildSealFeedbackUrl({ + buildFeedbackUrl('notifications', { name: 'Ada Lovelace', email: 'ada@example.org', }), ); + expect(url.origin + url.pathname).toBe(FEEDBACK_FORMS.notifications); expect(url.searchParams.get('usp')).toBe('pp_url'); expect(url.searchParams.get('entry.1481076408')).toBe('Ada Lovelace'); expect(url.searchParams.get('entry.1610387831')).toBe('ada@example.org'); }); it('omits the fields it does not have', () => { - const url = new URL(buildSealFeedbackUrl({ email: 'ada@example.org' })); + const url = new URL(buildFeedbackUrl('seal', { email: 'ada@example.org' })); expect(url.searchParams.has('entry.1481076408')).toBe(false); expect(url.searchParams.get('entry.1610387831')).toBe('ada@example.org'); }); it('ignores blank and null values rather than prefilling empty fields', () => { - const url = buildSealFeedbackUrl({ name: ' ', email: null }); + const url = buildFeedbackUrl('seal', { name: ' ', email: null }); expect(url).not.toContain('usp=pp_url'); expect(url).not.toContain('entry.'); }); it('trims surrounding whitespace before prefilling', () => { - const url = new URL(buildSealFeedbackUrl({ name: ' Ada Lovelace ' })); + const url = new URL(buildFeedbackUrl('seal', { name: ' Ada Lovelace ' })); expect(url.searchParams.get('entry.1481076408')).toBe('Ada Lovelace'); }); diff --git a/src/app/utils/feedback-url.ts b/src/app/utils/feedback-url.ts new file mode 100644 index 00000000..71592ea0 --- /dev/null +++ b/src/app/utils/feedback-url.ts @@ -0,0 +1,62 @@ +/** + * Google Forms collecting feedback on features in early release. + * + * Each entry is the canonical `viewform` URL rather than its `forms.gle` short + * link: prefill parameters only survive on the long form, the short link drops + * the query string when it redirects. + */ +export const FEEDBACK_FORMS = { + seal: 'https://docs.google.com/forms/d/e/1FAIpQLSdKlJEdxA8Jz8g6Z04h3PsWbQ9qPsjp93qONrWvQR60xJT3-Q/viewform', + notifications: + 'https://docs.google.com/forms/d/e/1FAIpQLSdOLZYv7707SmS3DWL_wIX3L0Zodoc38XN0qyv-xKJ3B5XjuA/viewform', +} as const; + +export type FeedbackFormId = keyof typeof FEEDBACK_FORMS; + +/** + * Field ids taken from each form's own "Get pre-filled link" output. Every + * form above shares them because they were copied from the same template. + * They are stable for the life of a question, but deleting and re-adding the + * "Name" or "Email" question in a form mints a new id and silently stops the + * prefill - regenerate them from the form if prefilled values stop showing up, + * and give that form its own ids if they diverge. + */ +const NAME_ENTRY_ID = 'entry.1481076408'; +const EMAIL_ENTRY_ID = 'entry.1610387831'; + +export interface FeedbackPrefill { + name?: string | null; + email?: string | null; +} + +/** + * Builds the feedback form URL, prefilling the respondent's name and email + * when the app knows them. Blank or missing values are left out entirely so + * the form renders an empty field rather than an empty prefill. With no + * prefill this is the bare form URL - what the server renders. + */ +export function buildFeedbackUrl( + form: FeedbackFormId, + prefill: FeedbackPrefill = {}, +): string { + const url = new URL(FEEDBACK_FORMS[form]); + const name = prefill.name?.trim() ?? ''; + const email = prefill.email?.trim() ?? ''; + + if (name === '' && email === '') { + return url.toString(); + } + + // Google's own marker for a prefilled link; without it the form ignores the + // entry parameters. + url.searchParams.set('usp', 'pp_url'); + + if (name !== '') { + url.searchParams.set(NAME_ENTRY_ID, name); + } + if (email !== '') { + url.searchParams.set(EMAIL_ENTRY_ID, email); + } + + return url.toString(); +} diff --git a/src/app/utils/seal-feedback-url.ts b/src/app/utils/seal-feedback-url.ts deleted file mode 100644 index c56fce7b..00000000 --- a/src/app/utils/seal-feedback-url.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * It's a redirect to a google form - */ -const SEAL_FEEDBACK_FORM_URL = 'https://share.mobilitydata.org/sealfeedback'; - -/** - * Field ids taken from the form's own "Get pre-filled link" output. They are - * stable for the life of a question, but deleting and re-adding the "Name" or - * "Email" question in the form mints a new id and silently stops the prefill - - * regenerate them from the form if prefilled values stop showing up. - */ -const NAME_ENTRY_ID = 'entry.1481076408'; -const EMAIL_ENTRY_ID = 'entry.1610387831'; - -/** The form with nothing prefilled - what the server renders. */ -export const SEAL_FEEDBACK_URL = SEAL_FEEDBACK_FORM_URL; - -export interface SealFeedbackPrefill { - name?: string | null; - email?: string | null; -} - -/** - * Builds the feedback form URL, prefilling the respondent's name and email - * when the app knows them. Blank or missing values are left out entirely so - * the form renders an empty field rather than an empty prefill. - */ -export function buildSealFeedbackUrl( - prefill: SealFeedbackPrefill = {}, -): string { - const url = new URL(SEAL_FEEDBACK_FORM_URL); - const name = prefill.name?.trim() ?? ''; - const email = prefill.email?.trim() ?? ''; - - if (name === '' && email === '') { - return url.toString(); - } - - // Google's own marker for a prefilled link; without it the form ignores the - // entry parameters. - url.searchParams.set('usp', 'pp_url'); - - if (name !== '') { - url.searchParams.set(NAME_ENTRY_ID, name); - } - if (email !== '') { - url.searchParams.set(EMAIL_ENTRY_ID, email); - } - - return url.toString(); -}