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
2 changes: 1 addition & 1 deletion shared/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface IUserImpact {
[year: number]: IImpactDataField[];
}

export type IImpactYear = 2019 | 2020 | 2021 | 2022 | 2023 | 2024;
export type IImpactYear = 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025;

export type INotificationUpdate = {
_id: string;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/User/impact/ImpactMissing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {
year: IImpactYear;
}

const isAllInvisible = (fields, visibleFields) => {
const isAllInvisible = (fields?: IImpactDataField[], visibleFields?: IImpactDataField[]) => {
if (visibleFields && visibleFields.length === 0 && fields && fields.length > 0) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/User/impact/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { IImpactYear } from 'oa-shared';

export const IMPACT_REPORT_LINKS = {
2024: 'https://www.preciousplastic.com/impact/2025',
2023: 'https://www.preciousplastic.com/impact/2024',
2022: 'https://www.preciousplastic.com/impact/2023',
2019: 'https://www.preciousplastic.com/impact',
};

export const IMPACT_YEARS: IImpactYear[] = [2024, 2023, 2022, 2021, 2020, 2019];
export const IMPACT_YEARS: IImpactYear[] = [2025, 2024, 2023, 2022, 2021, 2020, 2019];
4 changes: 2 additions & 2 deletions src/pages/UserSettings/SettingsPageImpact.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('SettingsPageImpact', () => {
expect(wrapper.getAllByText('43,000 Kg of plastic', { exact: false })).toHaveLength(1);
expect(wrapper.getAllByText('45 volunteers', { exact: false })).toHaveLength(1);

expect(wrapper.getAllByText('Edit data', { exact: false })).toHaveLength(6);
expect(wrapper.getAllByText('Do you have impact data for this year?')).toHaveLength(5);
expect(wrapper.getAllByText('Edit data', { exact: false })).toHaveLength(7);
expect(wrapper.getAllByText('Do you have impact data for this year?')).toHaveLength(6);
});
});
});
19 changes: 15 additions & 4 deletions src/pages/UserSettings/content/fields/ImpactQuestion.field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ interface Props {
}

export const ImpactQuestionField = ({ field, formId }: Props) => {
const initialValue = typeof field.isVisible === 'boolean' ? field.isVisible : true;

return (
<Box sx={{ marginBottom: 3 }}>
<Label htmlFor={`${field.id}.value`} sx={{ marginBottom: 1 }}>
Expand Down Expand Up @@ -45,7 +43,20 @@ export const ImpactQuestionField = ({ field, formId }: Props) => {
name={`${field.id}.value`}
sx={{ background: 'white' }}
type="number"
formatOnBlur
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'e' || e.key === 'E' || e.key === '+' || e.key === '-') {
e.preventDefault();
}
}}
onInput={(e: React.FormEvent<HTMLInputElement>) => {
const target = e.target as HTMLInputElement;

target.value = target.value
.replaceAll('e', '')
.replaceAll('E', '')
.replaceAll('+', '')
.replaceAll('-', '');
}}
/>
</Box>

Expand All @@ -65,7 +76,7 @@ export const ImpactQuestionField = ({ field, formId }: Props) => {
<Field
component="input"
data-cy={`${formId}-field-${field.id}-isVisible`}
initialValue={initialValue}
initialValue={true}
name={`${field.id}.isVisible`}
type="checkbox"
/>
Expand Down
12 changes: 3 additions & 9 deletions src/pages/UserSettings/content/impactQuestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export interface IImpactQuestion {
icon: string;
description: string;
label: string;
isVisible: boolean;
value?: number;
suffix?: string;
prefix?: string;
Expand All @@ -13,38 +12,33 @@ export const impactQuestions: IImpactQuestion[] = [
{
id: 'plastic',
icon: 'plastic',
description: 'How many KGs of plastic recycled have you recycled in that year?',
description: ' How many KGs of plastic have you recycled?',
label: 'plastic recycled',
suffix: 'Kg of',
isVisible: true,
},
{
id: 'revenue',
icon: 'revenue',
description: 'What was your annual revenue (in USD)? By revenue we mean all money coming in.',
description: 'What was your annual revenue (in USD)?',
label: 'revenue',
prefix: 'USD',
isVisible: true,
},
{
id: 'employees',
icon: 'employee',
description: 'How many people did your project employ (you included)?',
description: 'How many people did you employ (you included)?',
label: 'full time employees',
isVisible: true,
},
{
id: 'volunteers',
icon: 'volunteer',
description: 'How many volunteers did you work with?',
label: 'volunteers',
isVisible: true,
},
{
id: 'machines',
icon: 'machine',
description: 'How many machines did you build?',
label: 'machines built',
isVisible: true,
},
];
3 changes: 1 addition & 2 deletions src/pages/UserSettings/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { sortImpactYearDisplayFields, transformImpactData, transformImpactInputs

describe('transformImpactData', () => {
it('returns data structured as field inputs', () => {
const description =
'What was your annual revenue (in USD)? By revenue we mean all money coming in.';
const description = 'What was your annual revenue (in USD)?';

const impactFields = [
{
Expand Down
Loading