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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(<TestComponent />);

userEvent.click(await findByRole('button', { name: 'Dismiss' }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ interface SentGoalCardProps {

const SentGoalCard: React.FC<SentGoalCardProps> = ({ 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();
Expand Down
Loading