Skip to content
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
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion messages/fr.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<SortKey | null>(null);
const [order, setOrder] = React.useState<'asc' | 'desc'>('asc');

Expand Down Expand Up @@ -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 && <FeedbackButton form='notifications' />}
<Snackbar
open={actionError !== null}
autoHideDuration={4000}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getTranslations } from 'next-intl/server';
import CardSectionTitle from '../../../components/CardSectionTitle';
import SectionContainer from '../../../components/SectionContainer';
import SealOfReliability from '../../../components/SealOfReliability';
import SealFeedbackButton from '../../../components/SealFeedbackButton';
import FeedbackButton from '../../../components/FeedbackButton';
import { accordionStyle } from '../../../components/accordionStyle';
import { Link as LocaleLink } from '../../../../i18n/navigation';
import {
Expand All @@ -50,7 +50,7 @@ export default async function SealOfReliabilityDescriptionPage(): Promise<ReactE
}}
maxWidth='lg'
>
<SealFeedbackButton />
<FeedbackButton form='seal' />

<SectionContainer sx={{ mt: 0 }} maxWidth='lg'>
<Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import SectionContainer from '../../../../components/SectionContainer';
import CardSectionTitle from '../../../../components/CardSectionTitle';
import BreadcrumbNavigation from '../../../../components/BreadcrumbNavigation';
import SealOfReliability from '../../../../components/SealOfReliability';
import SealFeedbackButton from '../../../../components/SealFeedbackButton';
import FeedbackButton from '../../../../components/FeedbackButton';
import {
GTFS_VALIDATOR_URL,
clockStartEntries,
Expand Down Expand Up @@ -110,7 +110,7 @@ export default async function HowItIsCalculatedPage(): Promise<ReactElement> {

return (
<Container component='main' sx={{ width: '100%', m: 'auto' }} maxWidth='lg'>
<SealFeedbackButton />
<FeedbackButton form='seal' />

<BreadcrumbNavigation
crumbs={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ import { useTranslations } from 'next-intl';
import { useAppSelector } from '../hooks';
import { selectUserProfile } from '../store/profile-selectors';
import { useAuthSession } from './AuthSessionProvider';
import {
buildSealFeedbackUrl,
SEAL_FEEDBACK_URL,
} from '../utils/seal-feedback-url';
import { buildFeedbackUrl, type FeedbackFormId } from '../utils/feedback-url';

interface FeedbackButtonProps {
/** Which feature's feedback form the button opens. */
form: FeedbackFormId;
}

/** Per-form accessible label: the visible label is the same for every form. */
const ARIA_LABEL_KEYS = {
seal: 'sealFeedbackButtonAriaLabel',
notifications: 'notificationsFeedbackButtonAriaLabel',
} as const satisfies Record<FeedbackFormId, string>;

/**
*
* 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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 (
Expand All @@ -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',
Expand All @@ -80,15 +95,15 @@ export default function SealFeedbackButton(): ReactElement {
}}
startIcon={<FeedbackOutlinedIcon fontSize='small' aria-hidden />}
>
{t('sealFeedbackButtonLabel')}
{t('feedbackButtonLabel')}
</Button>
<Fab
color='primary'
href={feedbackUrl}
target='_blank'
rel='noreferrer'
data-testid='seal-feedback-fab'
aria-label={t('sealFeedbackButtonAriaLabel')}
data-testid={`${form}-feedback-fab`}
aria-label={t(ARIA_LABEL_KEYS[form])}
sx={{
display: { xs: 'flex', lg: 'none' },
position: 'fixed',
Expand Down
4 changes: 2 additions & 2 deletions src/app/screens/Feed/components/FeedReliabilityView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { getCoverageWindowLength } from '../lib/continuous-coverage';
import { getLatestCoverageWindow } from '../lib/fresh-coverage';
import { displayFormattedDate } from '../../../utils/date';
import SectionContainer from '../../../components/SectionContainer';
import SealFeedbackButton from '../../../components/SealFeedbackButton';
import FeedbackButton from '../../../components/FeedbackButton';

interface Props {
feed: AllFeedType;
Expand Down Expand Up @@ -103,7 +103,7 @@ export default async function FeedReliabilityView({
>
<ScrollToTop />
<CssBaseline />
<SealFeedbackButton />
<FeedbackButton form='seal' />
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<SectionContainer maxWidth='xl'>
<Box sx={{ position: 'relative' }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<keyof typeof FEEDBACK_FORMS>)(
'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');
});
Expand Down
62 changes: 62 additions & 0 deletions src/app/utils/feedback-url.ts
Original file line number Diff line number Diff line change
@@ -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();
}
51 changes: 0 additions & 51 deletions src/app/utils/seal-feedback-url.ts

This file was deleted.

Loading