diff --git a/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.test.tsx b/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.test.tsx
index 7e5f0d904..ab620a022 100644
--- a/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.test.tsx
+++ b/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.test.tsx
@@ -23,8 +23,8 @@ import {
} from './NewStaffGoalReadyCard.generated';
const accountListId = 'account-list-1';
-const goalId = 'goal-1';
-const optionKey = `new_staff_goal_acknowledged_${goalId}`;
+const goalId = 'a1b2c3d4-e5f6-4a7b-8c9d-0e1f';
+const optionKey = 'new_staff_goal_acknowledged_a1b2c3d4_e5f6_4a7b_8c9d_0e1f';
const sentFigures = { monthlyGoal: 4602.66, specialNeedsTotal: 2500 };
const router = {
@@ -55,7 +55,7 @@ const userOptionByKey = (
if (args.key === 'user_type_verified') {
return { key: args.key, value: userGroupVerified ? 'true' : 'false' };
}
- if (acknowledged === null) {
+ if (acknowledged === null || args.key !== optionKey) {
return null;
}
return {
@@ -273,7 +273,7 @@ describe('NewStaffGoalReadyCard', () => {
expect(queryByRole('heading')).not.toBeInTheDocument();
});
- it('dismissing saves the current figures and hides the card', async () => {
+ it('dismissing saves the current figures under a key the API accepts and hides the card', async () => {
const { findByRole, queryByRole } = render();
userEvent.click(await findByRole('button', { name: 'Dismiss' }));
diff --git a/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.tsx b/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.tsx
index fae48f0ff..0999fdc97 100644
--- a/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.tsx
+++ b/src/components/Dashboard/NewStaffGoalReadyCard/NewStaffGoalReadyCard.tsx
@@ -96,7 +96,8 @@ interface SentGoalCardProps {
const SentGoalCard: React.FC = ({ accountListId, goal }) => {
const { t } = useTranslation();
- const optionKey = `new_staff_goal_acknowledged_${goal.id}`;
+ // The API only accepts letters, numbers and underscores in option keys, and goal ids are UUIDs.
+ const optionKey = `new_staff_goal_acknowledged_${goal.id.replace(/[^A-Za-z0-9_]/g, '_')}`;
// Read the option from the query directly; useUserPreference applies it a frame late and flashes the card.
const { data } = useUserOptionQuery({ variables: { key: optionKey } });
const [updateUserOption] = useUpdateUserOptionMutation();