From 54caeb263dcdbc9db70704b9a73166a4ad1a75fa Mon Sep 17 00:00:00 2001 From: Ben Furber Date: Wed, 23 Oct 2024 14:23:47 +0100 Subject: [PATCH] feat: change collection profile to use tags --- .../assets/images/plastic-types/hdpe.svg | 1 - .../assets/images/plastic-types/ldpe.svg | 8 - .../assets/images/plastic-types/other.svg | 1 - .../assets/images/plastic-types/pet.svg | 1 - .../assets/images/plastic-types/pp.svg | 1 - .../assets/images/plastic-types/ps.svg | 1 - .../assets/images/plastic-types/pvc.svg | 1 - .../cypress/src/integration/settings.spec.ts | 57 +--- .../cypress/src/support/CustomAssertations.ts | 20 +- packages/cypress/src/support/commandsUi.ts | 49 +--- shared/data/profileTags.ts | 42 +++ shared/mocks/data/users.ts | 14 - shared/models/user.ts | 23 -- src/assets/images/plastic-types/hdpe.svg | 1 - src/assets/images/plastic-types/ldpe.svg | 8 - src/assets/images/plastic-types/other.svg | 1 - src/assets/images/plastic-types/pet.svg | 1 - src/assets/images/plastic-types/pp.svg | 1 - src/assets/images/plastic-types/ps.svg | 1 - src/assets/images/plastic-types/pvc.svg | 1 - src/pages/User/content/SpaceProfile.tsx | 88 +------ .../SettingsPageUserProfile.test.tsx | 9 +- .../UserSettings/SettingsPageUserProfile.tsx | 17 +- .../content/fields/CustomCheckbox.field.tsx | 106 -------- .../fields/OpeningHoursPicker.field.tsx | 246 ------------------ .../content/sections/Collection.section.tsx | 164 ------------ src/pages/UserSettings/labels.ts | 9 - 27 files changed, 62 insertions(+), 810 deletions(-) delete mode 100755 packages/components/assets/images/plastic-types/hdpe.svg delete mode 100755 packages/components/assets/images/plastic-types/ldpe.svg delete mode 100755 packages/components/assets/images/plastic-types/other.svg delete mode 100755 packages/components/assets/images/plastic-types/pet.svg delete mode 100755 packages/components/assets/images/plastic-types/pp.svg delete mode 100755 packages/components/assets/images/plastic-types/ps.svg delete mode 100755 packages/components/assets/images/plastic-types/pvc.svg delete mode 100755 src/assets/images/plastic-types/hdpe.svg delete mode 100755 src/assets/images/plastic-types/ldpe.svg delete mode 100755 src/assets/images/plastic-types/other.svg delete mode 100755 src/assets/images/plastic-types/pet.svg delete mode 100755 src/assets/images/plastic-types/pp.svg delete mode 100755 src/assets/images/plastic-types/ps.svg delete mode 100755 src/assets/images/plastic-types/pvc.svg delete mode 100644 src/pages/UserSettings/content/fields/CustomCheckbox.field.tsx delete mode 100644 src/pages/UserSettings/content/fields/OpeningHoursPicker.field.tsx delete mode 100644 src/pages/UserSettings/content/sections/Collection.section.tsx diff --git a/packages/components/assets/images/plastic-types/hdpe.svg b/packages/components/assets/images/plastic-types/hdpe.svg deleted file mode 100755 index 4d5a5fefb6..0000000000 --- a/packages/components/assets/images/plastic-types/hdpe.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type hdpe \ No newline at end of file diff --git a/packages/components/assets/images/plastic-types/ldpe.svg b/packages/components/assets/images/plastic-types/ldpe.svg deleted file mode 100755 index 2538181824..0000000000 --- a/packages/components/assets/images/plastic-types/ldpe.svg +++ /dev/null @@ -1,8 +0,0 @@ -icon plastic type ldpe - - - - - - - \ No newline at end of file diff --git a/packages/components/assets/images/plastic-types/other.svg b/packages/components/assets/images/plastic-types/other.svg deleted file mode 100755 index a62c4cd4f7..0000000000 --- a/packages/components/assets/images/plastic-types/other.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type other \ No newline at end of file diff --git a/packages/components/assets/images/plastic-types/pet.svg b/packages/components/assets/images/plastic-types/pet.svg deleted file mode 100755 index f99758e7c9..0000000000 --- a/packages/components/assets/images/plastic-types/pet.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type pet \ No newline at end of file diff --git a/packages/components/assets/images/plastic-types/pp.svg b/packages/components/assets/images/plastic-types/pp.svg deleted file mode 100755 index 46dd3aaa01..0000000000 --- a/packages/components/assets/images/plastic-types/pp.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type pp \ No newline at end of file diff --git a/packages/components/assets/images/plastic-types/ps.svg b/packages/components/assets/images/plastic-types/ps.svg deleted file mode 100755 index 64fad655ab..0000000000 --- a/packages/components/assets/images/plastic-types/ps.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type ps \ No newline at end of file diff --git a/packages/components/assets/images/plastic-types/pvc.svg b/packages/components/assets/images/plastic-types/pvc.svg deleted file mode 100755 index a8e2c74701..0000000000 --- a/packages/components/assets/images/plastic-types/pvc.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type pvc \ No newline at end of file diff --git a/packages/cypress/src/integration/settings.spec.ts b/packages/cypress/src/integration/settings.spec.ts index 2acfb3b1b8..80e0888a4b 100644 --- a/packages/cypress/src/integration/settings.spec.ts +++ b/packages/cypress/src/integration/settings.spec.ts @@ -377,33 +377,7 @@ describe('[Settings]', () => { const description = 'We accept plastic currencies: Bottle, Nylon Bags, Plastic Lids/Straws' const displayName = 'settings_community_new' - const openTimes = [ - { - index: 0, - day: 'Monday', - from: '09:00 AM', - to: '06:00 PM', - }, - { - index: 1, - day: 'Tuesday', - from: '09:00 AM', - to: '06:00 PM', - }, - { - index: 2, - day: 'Wednesday', - from: '10:00 AM', - to: '08:00 PM', - }, - { - index: 3, - day: 'Friday', - from: '05:00 AM', - to: '02:00 PM', - }, - ] - const plasticTypes = ['hdpe', 'other'] + const plasticTypes = ['HDPE', 'LDPE'] const profileType = 'collection-point' const user = generateNewUserDetails() const url = 'http://www.facebook.com/settings_plastic_new' @@ -418,6 +392,10 @@ describe('[Settings]', () => { cy.get('[data-cy=save]').click() cy.get('[data-cy=errors-container]').should('be.visible') + cy.step('Set profile tags') + cy.selectTag(plasticTypes[0], '[data-cy=tag-select]') + cy.selectTag(plasticTypes[1], '[data-cy=tag-select]') + cy.step('Populate profile') cy.setSettingBasicUserInfo({ displayName, @@ -431,16 +409,6 @@ describe('[Settings]', () => { url, }) - cy.step('Update collection specific section') - openTimes.forEach((openTime) => { - cy.setSettingAddOpeningTime(openTime) - }) - cy.setSettingDeleteOpeningTime(1, false) - cy.setSettingDeleteOpeningTime(2, true) - - cy.get(`[data-cy=plastic-${plasticTypes[0]}]`).click() - cy.get(`[data-cy=plastic-${plasticTypes[1]}]`).click() - cy.saveSettingsForm() cy.step('Updated settings display on main profile tab') @@ -452,19 +420,8 @@ describe('[Settings]', () => { cy.get('[data-cy="active-image"]') .should('have.attr', 'src') .and('include', coverImage) - - cy.step('Updated collection specific section displayed') - cy.get(`[data-cy=plastic-type-${plasticTypes[0]}]`) - cy.get(`[data-cy=plastic-type-${plasticTypes[1]}]`) - cy.contains( - `${openTimes[0].day}: ${openTimes[0].from} - ${openTimes[0].to}`, - ) - cy.contains( - `${openTimes[1].day}: ${openTimes[1].from} - ${openTimes[1].to}`, - ) - cy.contains( - `${openTimes[3].day}: ${openTimes[3].from} - ${openTimes[3].to}`, - ) + cy.contains(plasticTypes[0]) + cy.contains(plasticTypes[1]) cy.step('Updated settings display on contact tab') cy.get('[data-cy="contact-tab"]').click() diff --git a/packages/cypress/src/support/CustomAssertations.ts b/packages/cypress/src/support/CustomAssertations.ts index 833c221c97..c6f004905a 100644 --- a/packages/cypress/src/support/CustomAssertations.ts +++ b/packages/cypress/src/support/CustomAssertations.ts @@ -1,12 +1,12 @@ import chaiSubset from 'chai-subset' -import type { ProfileTypeName } from 'oa-shared' import type { IHowto, IHowtoStep, IResearchDB, IUserDB, -} from '../../../../src/models' + ProfileTypeName, +} from 'oa-shared' declare global { namespace Chai { @@ -171,19 +171,6 @@ const eqSettings = (chaiObj) => { expect(subject.workspaceType, 'workspaceType').to.containSubset( expected.workspaceType, ) - const machineExpertiseAssert: Assert = (subject, expected) => - expect(subject.machineBuilderXp, 'MachineBuilderXp').to.containSubset( - expected.machineBuilderXp, - ) - const openingHoursAssert: Assert = (subject, expected) => - expect(subject.openingHours, 'OpeningHours').to.containSubset( - expected.openingHours, - ) - const plasticTypeAssert: Assert = (subject, expected) => - expect( - subject.collectedPlasticTypes, - 'CollectedPlasticTypes', - ).to.containSubset(expected.collectedPlasticTypes) const assertMap: { [key in ProfileTypeName]: ChainAssert @@ -205,7 +192,6 @@ const eqSettings = (chaiObj) => { coverImageAssert, linkAssert, locationAssert, - machineExpertiseAssert, ), 'community-builder': new ChainAssert( basicInfoAssert, @@ -218,8 +204,6 @@ const eqSettings = (chaiObj) => { coverImageAssert, linkAssert, locationAssert, - openingHoursAssert, - plasticTypeAssert, ), space: undefined, } diff --git a/packages/cypress/src/support/commandsUi.ts b/packages/cypress/src/support/commandsUi.ts index 15278bff8a..6c0c4ba57f 100644 --- a/packages/cypress/src/support/commandsUi.ts +++ b/packages/cypress/src/support/commandsUi.ts @@ -1,7 +1,7 @@ import { form } from '../../../../src/pages/UserSettings/labels' import { generateNewUserDetails } from '../utils/TestUtils' -import type { IUser } from '../../../../src/models/user.models' +import type { IUser } from 'oa-shared' export enum UserMenuItem { Profile = 'Profile', @@ -23,13 +23,6 @@ interface IMapPin { locationName: string } -interface IOpeningTime { - index: number - day: string - from: string - to: string -} - declare global { namespace Cypress { interface Chainable { @@ -63,9 +56,7 @@ declare global { **/ selectTag(tagName: string, selector?: string): Chainable setSettingAddContactLink(link: ILink) - setSettingAddOpeningTime(openingTime: IOpeningTime) setSettingBasicUserInfo(info: IInfo) - setSettingDeleteOpeningTime(index: number, confirmed: boolean) setSettingFocus(focus: string) setSettingImage(image: string, selector: string) setSettingImpactData(year: number, fields) @@ -108,31 +99,6 @@ Cypress.Commands.add('setSettingAddContactLink', (link: ILink) => { .blur({ force: true }) }) -Cypress.Commands.add( - 'setSettingAddOpeningTime', - (openingTime: IOpeningTime) => { - const selectOption = (selector: string, selectedValue: string) => { - cy.selectTag(selectedValue, selector) - } - - if (openingTime.index > 0) { - cy.get('[data-cy=add-opening-time]').click() - } - selectOption( - `[data-cy=opening-time-day-${openingTime.index}]`, - openingTime.day, - ) - selectOption( - `[data-cy=opening-time-from-${openingTime.index}]`, - openingTime.from, - ) - selectOption( - `[data-cy=opening-time-to-${openingTime.index}]`, - openingTime.to, - ) - }, -) - Cypress.Commands.add('setSettingBasicUserInfo', (info: IInfo) => { const { country, description, displayName } = info @@ -142,19 +108,6 @@ Cypress.Commands.add('setSettingBasicUserInfo', (info: IInfo) => { country && cy.selectTag(country, '[data-cy=location-dropdown]') }) -Cypress.Commands.add( - 'setSettingDeleteOpeningTime', - (index: number, confirmed: boolean) => { - cy.viewport('macbook-13') - cy.get(`[data-cy=delete-opening-time-${index}-desk]`).click() - if (confirmed) { - cy.get('[data-cy=confirm-delete]').click() - } else { - cy.get('[data-cy=cancel-delete]').click() - } - }, -) - Cypress.Commands.add('setSettingFocus', (focus: string) => { cy.get(`[data-cy=${focus}]`).click() }) diff --git a/shared/data/profileTags.ts b/shared/data/profileTags.ts index 8a108d70a5..2fd0afeee0 100644 --- a/shared/data/profileTags.ts +++ b/shared/data/profileTags.ts @@ -31,4 +31,46 @@ export const profileTags: ITag[] = [ _deleted: false, label: 'Mould Making', }, + { + _id: '4ax6TzzVsAtG6Au8nEXJ', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'PET', + }, + { + _id: 'farYGhuqJc6wrAwa2xyx', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'HDPE', + }, + { + _id: 'XjBLmxaYi2Hu3H2n4QBw', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'PVC', + }, + { + _id: 'HDNJjX4ohKFfM7YznEpL', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'LDPE', + }, + { + _id: 'P7pk8KAQwzqHLqhGUvoy', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'PP', + }, + { + _id: '3PLMJ7mXxZFRqrTLcM2h', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'PS', + }, + { + _id: '3E6Eyxf7EYmPLXeF8nd3', + _created: '2018-01-02T00:00:00.001Z', + _deleted: false, + label: 'Other Plastics', + }, ] diff --git a/shared/mocks/data/users.ts b/shared/mocks/data/users.ts index 1f9f1810be..7660b8e676 100644 --- a/shared/mocks/data/users.ts +++ b/shared/mocks/data/users.ts @@ -191,8 +191,6 @@ export const users = { _id: 'settings_community_new', profileType: null, coverImages: [], - collectedPlasticTypes: null, - openingHours: [], location: null, verified: true, _modified: '2020-01-07T12:15:08.726Z', @@ -209,9 +207,7 @@ export const users = { about: null, }, settings_machine_new: { - collectedPlasticTypes: null, location: null, - openingHours: [], verified: true, _modified: '2020-01-07T12:14:50.354Z', _created: '2020-01-07T12:14:50.354Z', @@ -242,8 +238,6 @@ export const users = { _id: 'settings_member_new', profileType: null, coverImages: [], - collectedPlasticTypes: null, - openingHours: [], location: null, verified: true, _modified: '2020-01-07T12:14:30.030Z', @@ -251,8 +245,6 @@ export const users = { displayName: 'settings_member_new', }, settings_plastic_new: { - collectedPlasticTypes: [], - openingHours: [], location: null, verified: true, _modified: '2020-01-07T12:15:42.218Z', @@ -272,8 +264,6 @@ export const users = { coverImages: [], }, settings_workplace_empty: { - collectedPlasticTypes: [], - openingHours: [], location: null, verified: true, _modified: '2020-01-07T12:15:42.218Z', @@ -293,7 +283,6 @@ export const users = { coverImages: [], }, settings_workplace_new: { - openingHours: [], location: null, verified: true, _modified: '2020-01-07T12:14:15.081Z', @@ -311,7 +300,6 @@ export const users = { _id: 'settings_workplace_new', profileType: 'workspace', coverImages: [], - collectedPlasticTypes: null, email: 'settings_workplace_new@test.com', password: 'test1234', userRoles: [UserRole.BETA_TESTER], @@ -347,7 +335,6 @@ export const users = { isContactableByPublic: false, }, mapview_testing_rejected: { - openingHours: [], location: null, verified: true, _modified: '2020-01-07T12:14:15.081Z', @@ -365,7 +352,6 @@ export const users = { _id: 'mapview_testing_rejected', profileType: 'workspace', coverImages: [], - collectedPlasticTypes: null, email: 'mapview_testing_rejected@test.com', password: 'mapview_testing_rejected@test.com', }, diff --git a/shared/models/user.ts b/shared/models/user.ts index d262e15afe..5a464db3bf 100644 --- a/shared/models/user.ts +++ b/shared/models/user.ts @@ -101,15 +101,6 @@ export type ProfileTypeName = // Below are primarily used for PP -export type PlasticTypeLabel = - | 'pet' - | 'hdpe' - | 'pvc' - | 'ldpe' - | 'pp' - | 'ps' - | 'other' - export type WorkspaceType = | 'shredder' | 'sheetpress' @@ -117,12 +108,6 @@ export type WorkspaceType = | 'injection' | 'mix' -export interface IPlasticType { - label: PlasticTypeLabel - number: string - imageSrc?: string -} - export interface IProfileType { label: ProfileTypeName imageSrc?: string @@ -137,12 +122,6 @@ export interface IWorkspaceType { subText?: string } -export interface IOpeningHours { - day: string - openFrom: string - openTo: string -} - export type UserMention = { username: string location: string @@ -191,9 +170,7 @@ export interface IUser { // Primary PP profile type related fields profileType: ProfileTypeName workspaceType?: WorkspaceType | null // <-- to-do replace with tags - collectedPlasticTypes?: PlasticTypeLabel[] | null // <-- to-do replace with tags mapPinDescription?: string | null - openingHours?: IOpeningHours[] } export interface IUserBadges { diff --git a/src/assets/images/plastic-types/hdpe.svg b/src/assets/images/plastic-types/hdpe.svg deleted file mode 100755 index 4d5a5fefb6..0000000000 --- a/src/assets/images/plastic-types/hdpe.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type hdpe \ No newline at end of file diff --git a/src/assets/images/plastic-types/ldpe.svg b/src/assets/images/plastic-types/ldpe.svg deleted file mode 100755 index 2538181824..0000000000 --- a/src/assets/images/plastic-types/ldpe.svg +++ /dev/null @@ -1,8 +0,0 @@ -icon plastic type ldpe - - - - - - - \ No newline at end of file diff --git a/src/assets/images/plastic-types/other.svg b/src/assets/images/plastic-types/other.svg deleted file mode 100755 index a62c4cd4f7..0000000000 --- a/src/assets/images/plastic-types/other.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type other \ No newline at end of file diff --git a/src/assets/images/plastic-types/pet.svg b/src/assets/images/plastic-types/pet.svg deleted file mode 100755 index f99758e7c9..0000000000 --- a/src/assets/images/plastic-types/pet.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type pet \ No newline at end of file diff --git a/src/assets/images/plastic-types/pp.svg b/src/assets/images/plastic-types/pp.svg deleted file mode 100755 index 46dd3aaa01..0000000000 --- a/src/assets/images/plastic-types/pp.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type pp \ No newline at end of file diff --git a/src/assets/images/plastic-types/ps.svg b/src/assets/images/plastic-types/ps.svg deleted file mode 100755 index 64fad655ab..0000000000 --- a/src/assets/images/plastic-types/ps.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type ps \ No newline at end of file diff --git a/src/assets/images/plastic-types/pvc.svg b/src/assets/images/plastic-types/pvc.svg deleted file mode 100755 index a8e2c74701..0000000000 --- a/src/assets/images/plastic-types/pvc.svg +++ /dev/null @@ -1 +0,0 @@ -icon plastic type pvc \ No newline at end of file diff --git a/src/pages/User/content/SpaceProfile.tsx b/src/pages/User/content/SpaceProfile.tsx index 8a2c163adf..123a251953 100644 --- a/src/pages/User/content/SpaceProfile.tsx +++ b/src/pages/User/content/SpaceProfile.tsx @@ -8,15 +8,7 @@ import { Username, UserStatistics, } from 'oa-components' -import { ExternalLinkLabel, ProfileTypeList, UserRole } from 'oa-shared' -// Plastic types -import HDPEIcon from 'src/assets/images/plastic-types/hdpe.svg' -import LDPEIcon from 'src/assets/images/plastic-types/ldpe.svg' -import OtherIcon from 'src/assets/images/plastic-types/other.svg' -import PETIcon from 'src/assets/images/plastic-types/pet.svg' -import PPIcon from 'src/assets/images/plastic-types/pp.svg' -import PSIcon from 'src/assets/images/plastic-types/ps.svg' -import PVCIcon from 'src/assets/images/plastic-types/pvc.svg' +import { ExternalLinkLabel, UserRole } from 'oa-shared' import { AuthWrapper } from 'src/common/AuthWrapper' import { ProfileTags } from 'src/common/ProfileTags' import { isPreciousPlastic } from 'src/config/config' @@ -30,7 +22,6 @@ import { Card, Flex, Heading, - Image, Paragraph, } from 'theme-ui' @@ -40,7 +31,7 @@ import { heading } from '../impact/labels' import UserContactAndLinks from './UserContactAndLinks' import UserCreatedDocuments from './UserCreatedDocuments' -import type { IOpeningHours, IUser, PlasticTypeLabel } from 'oa-shared' +import type { IUser } from 'oa-shared' import type { UserCreatedDocs } from '../types' interface IProps { @@ -48,65 +39,6 @@ interface IProps { docs: UserCreatedDocs | undefined } -const renderPlasticTypes = (plasticTypes: Array) => { - const renderIcon = (type: string) => { - const iconMap = { - hdpe: HDPEIcon, - ldpe: LDPEIcon, - other: OtherIcon, - pet: PETIcon, - pp: PPIcon, - ps: PSIcon, - pvc: PVCIcon, - } - - const toRender = iconMap[type] - return ( - toRender && ( - - ) - ) - } - - return ( -
-

We collect the following plastic types:

- - {plasticTypes.map((plasticType) => { - return ( - - {renderIcon(plasticType)} - - ) - })} - -
- ) -} - -const renderOpeningHours = (openingHours: IOpeningHours[]) => ( -
-

We're open on:

- {openingHours.map((openingObj) => { - return ( -

- {openingObj.day}: {openingObj.openFrom} - {openingObj.openTo} -

- ) - })} -
-) - const getCoverImages = (user: IUser) => { if (user.coverImages && user.coverImages.length) { return user.coverImages @@ -233,7 +165,7 @@ export const SpaceProfile = ({ user, docs }: IProps) => { Contact - + { gap: [0, 0, 6], }} > - {tags && } {about && {about}} - - {profileType === ProfileTypeList.COLLECTION_POINT && - user.collectedPlasticTypes && - renderPlasticTypes(user.collectedPlasticTypes)} - - {profileType === ProfileTypeList.COLLECTION_POINT && - user.openingHours && - renderOpeningHours(user.openingHours)} - + { await waitFor(() => { expect(wrapper.queryByTestId('workspaceType')).toBeNull() - expect(wrapper.queryByTestId('CollectionSection')).toBeNull() - expect(wrapper.queryByTestId('CollectionSection')).toBeNull() expect(wrapper.queryByTestId('ProfileTags')).toBeNull() expect(wrapper.getAllByTestId('UserInfosSection')).toHaveLength(1) expect(wrapper.queryByTestId('PublicContactSection')).toBeNull() @@ -60,8 +58,7 @@ describe('UserSettings', () => { await waitFor(() => { expect(wrapper.queryByTestId('workspaceType')).toBeNull() - expect(wrapper.getAllByTestId('CollectionSection')).toHaveLength(1) - expect(wrapper.queryByTestId('ProfileTags')).toBeNull() + expect(wrapper.getAllByTestId('ProfileTags')).toHaveLength(1) expect(wrapper.getAllByTestId('UserInfosSection')).toHaveLength(1) expect(wrapper.getAllByTestId('PublicContactSection')).toHaveLength(1) expect(wrapper.getAllByTestId('userImage')).toHaveLength(1) @@ -79,7 +76,6 @@ describe('UserSettings', () => { await waitFor(() => { expect(wrapper.queryByTestId('workspaceType')).toBeNull() - expect(wrapper.queryByTestId('CollectionSection')).toBeNull() expect(wrapper.queryByTestId('ProfileTags')).toBeNull() expect(wrapper.getAllByTestId('UserInfosSection')).toHaveLength(1) expect(wrapper.getAllByTestId('PublicContactSection')).toHaveLength(1) @@ -98,7 +94,6 @@ describe('UserSettings', () => { await waitFor(() => { expect(wrapper.queryByTestId('workspaceType')).toBeNull() - expect(wrapper.queryByTestId('CollectionSection')).toBeNull() expect(wrapper.getAllByTestId('ProfileTags')).toHaveLength(1) expect(wrapper.getAllByTestId('UserInfosSection')).toHaveLength(1) expect(wrapper.getAllByTestId('PublicContactSection')).toHaveLength(1) @@ -117,7 +112,6 @@ describe('UserSettings', () => { await waitFor(() => { expect(wrapper.queryByTestId('workspaceType')).toBeNull() - expect(wrapper.queryByTestId('CollectionSection')).toBeNull() expect(wrapper.queryByTestId('ProfileTags')).toBeNull() expect(wrapper.getAllByTestId('UserInfosSection')).toHaveLength(1) expect(wrapper.getAllByTestId('PublicContactSection')).toHaveLength(1) @@ -136,7 +130,6 @@ describe('UserSettings', () => { await waitFor(() => { expect(wrapper.getAllByTestId('workspaceType')).toHaveLength(1) - expect(wrapper.queryByTestId('CollectionSection')).toBeNull() expect(wrapper.queryByTestId('ProfileTags')).toBeNull() expect(wrapper.getAllByTestId('UserInfosSection')).toHaveLength(1) expect(wrapper.getAllByTestId('PublicContactSection')).toHaveLength(1) diff --git a/src/pages/UserSettings/SettingsPageUserProfile.tsx b/src/pages/UserSettings/SettingsPageUserProfile.tsx index 81e1a515ff..3ef1ac5f85 100644 --- a/src/pages/UserSettings/SettingsPageUserProfile.tsx +++ b/src/pages/UserSettings/SettingsPageUserProfile.tsx @@ -13,7 +13,6 @@ import { Flex } from 'theme-ui' import { v4 as uuid } from 'uuid' import { EnvironmentContext } from '../common/EnvironmentContext' -import { CollectionSection } from './content/sections/Collection.section' import { FocusSection } from './content/sections/Focus.section' import { ProfileTags } from './content/sections/ProfileTags.section' import { PublicContactSection } from './content/sections/PublicContact.section' @@ -105,9 +104,7 @@ export const SettingsPageUserProfile = () => { links, location: user.location || null, about: user.about || null, - openingHours: user.openingHours || [{}], workspaceType: user.workspaceType || null, - collectedPlasticTypes: user.collectedPlasticTypes || null, isContactableByPublic: user.isContactableByPublic || DEFAULT_PUBLIC_CONTACT_PREFERENCE, userImage: user.userImage || null, @@ -160,18 +157,8 @@ export const SettingsPageUserProfile = () => { )} - {values.profileType === ProfileTypeList.COLLECTION_POINT && ( - - )} - - {values.profileType === ProfileTypeList.MACHINE_BUILDER && ( + {(values.profileType === ProfileTypeList.MACHINE_BUILDER || + values.profileType === ProfileTypeList.COLLECTION_POINT) && ( )} diff --git a/src/pages/UserSettings/content/fields/CustomCheckbox.field.tsx b/src/pages/UserSettings/content/fields/CustomCheckbox.field.tsx deleted file mode 100644 index cf44ee9d03..0000000000 --- a/src/pages/UserSettings/content/fields/CustomCheckbox.field.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import React from 'react' -import { Image, Input, Text } from 'theme-ui' - -import { HiddenInput, Label } from '../elements' - -import type { FieldRenderProps } from 'react-final-form' - -interface IProps { - value: string - index: number - onChange: (index: number) => void - isSelected: boolean - imageSrc?: string - btnLabel?: string - fullWidth?: boolean - 'data-cy'?: string - required?: boolean -} - -type FieldProps = FieldRenderProps & { - children?: React.ReactNode - disabled?: boolean - 'data-cy'?: string - customOnBlur?: (event) => void -} - -const HiddenInputField = ({ input, meta, ...rest }: FieldProps) => ( - <> - - -) - -// validation - return undefined if no error (i.e. valid) -const isRequired = (value: any) => (value ? undefined : 'Required') - -export const CustomCheckbox = (props: IProps) => { - const { - value, - index, - imageSrc, - isSelected, - btnLabel, - fullWidth, - 'data-cy': dataCy, - required, - } = props - const classNames: Array = [] - if (isSelected) { - classNames.push('selected') - } - if (fullWidth) { - classNames.push('full-width') - } - - return ( - - ) -} diff --git a/src/pages/UserSettings/content/fields/OpeningHoursPicker.field.tsx b/src/pages/UserSettings/content/fields/OpeningHoursPicker.field.tsx deleted file mode 100644 index b294d165f9..0000000000 --- a/src/pages/UserSettings/content/fields/OpeningHoursPicker.field.tsx +++ /dev/null @@ -1,246 +0,0 @@ -import React, { useState } from 'react' -import { Field } from 'react-final-form' -import { Button, Modal } from 'oa-components' -import { SelectField } from 'src/common/Form/Select.field' -import { required } from 'src/utils/validators' -import { Flex, Text } from 'theme-ui' - -const WEEK_DAYS = [ - { - value: 'Monday', - label: 'Monday', - }, - { - value: 'Tuesday', - label: 'Tuesday', - }, - { - value: 'Wednesday', - label: 'Wednesday', - }, - { - value: 'Thursday', - label: 'Thursday', - }, - { - value: 'Friday', - label: 'Friday', - }, - { - value: 'Saturday', - label: 'Saturday', - }, - { - value: 'Sunday', - label: 'Sunday', - }, -] - -const OPENING_HOURS = [ - { - value: '01:00 AM', - label: '01:00 AM', - }, - { - value: '02:00 AM', - label: '02:00 AM', - }, - { - value: '03:00 AM', - label: '03:00 AM', - }, - { - value: '04:00 AM', - label: '04:00 AM', - }, - { - value: '05:00 AM', - label: '05:00 AM', - }, - { - value: '06:00 AM', - label: '06:00 AM', - }, - { - value: '07:00 AM', - label: '07:00 AM', - }, - { - value: '08:00 AM', - label: '08:00 AM', - }, - { - value: '09:00 AM', - label: '09:00 AM', - }, - { - value: '10:00 AM', - label: '10:00 AM', - }, - { - value: '11:00 AM', - label: '11:00 AM', - }, - { - value: '12:00 AM', - label: '12:00 AM', - }, - { - value: '01:00 PM', - label: '01:00 PM', - }, - { - value: '02:00 PM', - label: '02:00 PM', - }, - { - value: '03:00 PM', - label: '03:00 PM', - }, - { - value: '04:00 PM', - label: '04:00 PM', - }, - { - value: '05:00 PM', - label: '05:00 PM', - }, - { - value: '06:00 PM', - label: '06:00 PM', - }, - { - value: '07:00 PM', - label: '07:00 PM', - }, - { - value: '08:00 PM', - label: '08:00 PM', - }, - { - value: '09:00 PM', - label: '09:00 PM', - }, - { - value: '10:00 PM', - label: '10:00 PM', - }, - { - value: '11:00 PM', - label: '11:00 PM', - }, - { - value: '12:00 PM', - label: '12:00 PM', - }, -] - -interface IProps { - openingHoursValues?: string - index: number - onDelete: (index: number) => void -} -interface IState { - showDeleteModal: boolean - _toDocsList: boolean -} - -export const OpeningHoursPicker = (props: IProps) => { - const { openingHoursValues, index } = props - const [state, setState] = useState({ - showDeleteModal: false, - _toDocsList: false, - }) - - const toggleDeleteModal = () => { - setState((state) => ({ ...state, showDeleteModal: !state.showDeleteModal })) - } - const confirmDelete = () => { - toggleDeleteModal() - props.onDelete(props.index) - } - - return ( - - - - - - {index > 0 && ( - - )}{' '} - - - toggleDeleteModal()} - isOpen={state.showDeleteModal} - > - Are you sure you want to delete this schedule ? - - - - - - - - - - - ) -} diff --git a/src/pages/UserSettings/content/sections/Collection.section.tsx b/src/pages/UserSettings/content/sections/Collection.section.tsx deleted file mode 100644 index 21d06da873..0000000000 --- a/src/pages/UserSettings/content/sections/Collection.section.tsx +++ /dev/null @@ -1,164 +0,0 @@ -import * as React from 'react' -import { FieldArray } from 'react-final-form-arrays' -import { Button } from 'oa-components' -import Hdpe from 'src/assets/images/plastic-types/hdpe.svg' -import Ldpe from 'src/assets/images/plastic-types/ldpe.svg' -import Other from 'src/assets/images/plastic-types/other.svg' -import Pet from 'src/assets/images/plastic-types/pet.svg' -import PP from 'src/assets/images/plastic-types/pp.svg' -import PS from 'src/assets/images/plastic-types/ps.svg' -import Pvc from 'src/assets/images/plastic-types/pvc.svg' -import { fields, headings } from 'src/pages/UserSettings/labels' -import { Flex, Grid, Heading, Text } from 'theme-ui' - -import { FlexSectionContainer } from '../elements' -import { CustomCheckbox } from '../fields/CustomCheckbox.field' -import { OpeningHoursPicker } from '../fields/OpeningHoursPicker.field' - -import type { IPlasticType, IUser } from 'oa-shared' - -interface IProps { - formValues: IUser - required: boolean -} - -export const CollectionSection = (props: IProps) => { - const { required } = props - const { description, title } = fields.openingHours - - return ( - - - {headings.collection} - - - - {`${title} *`} - - {({ fields }) => ( - <> - {fields.map((name, index: number) => ( - { - fields.remove(fieldIndex) - }} - /> - ))} - {fields.length && fields.length < 7 && ( - - )} - - )} - - - - {`${fields.plastic.title}`} * - {required && ( - - {fields.plastic.description} - - )} - - - {({ fields }) => ( - <> - {PLASTIC_TYPES.map((plastic, index: number) => ( - { - if (fields.value && fields.value.length !== 0) { - if (fields.value.includes(plastic.label)) { - // eslint-disable-next-line - fields.value.map((value, selectedValIndex) => { - if (value === plastic.label) { - fields.remove(selectedValIndex) - } - }) - } else { - fields.push(plastic.label) - } - } else { - fields.push(plastic.label) - } - }} - imageSrc={plastic.imageSrc} - /> - ))} - - )} - - - - - - ) -} - -const PLASTIC_TYPES: IPlasticType[] = [ - { - label: 'pet', - number: '1', - imageSrc: Pet, - }, - { - label: 'hdpe', - number: '2', - imageSrc: Hdpe, - }, - { - label: 'pvc', - number: '3', - imageSrc: Pvc, - }, - { - label: 'ldpe', - number: '4', - imageSrc: Ldpe, - }, - { - label: 'pp', - number: '5', - imageSrc: PP, - }, - { - label: 'ps', - number: '6', - imageSrc: PS, - }, - { - label: 'other', - number: '7', - imageSrc: Other, - }, -] diff --git a/src/pages/UserSettings/labels.ts b/src/pages/UserSettings/labels.ts index cf09499c70..788082506b 100644 --- a/src/pages/UserSettings/labels.ts +++ b/src/pages/UserSettings/labels.ts @@ -104,17 +104,9 @@ export const fields: ILabels = { title: 'Old password', placeholder: 'Old password', }, - openingHours: { - description: 'add opening day', - title: 'Opening time(s)', - }, password: { title: 'Password', }, - plastic: { - description: 'Choose at least one plastic type', - title: 'Plastic types accepted', - }, publicContentPreference: { title: 'Contact Preference', description: @@ -150,7 +142,6 @@ export const headings = { accountSettings: 'Account settings', changeEmail: 'Change Email', changePassword: 'Change Password', - collection: 'Collection', createProfile: 'Create profile', editProfile: 'Edit profile', focus: 'Focus',