diff --git a/CHANGELOG.md b/CHANGELOG.md index e702b5a4b05d9b0e2f4f5459269edf24a1f19a06..3929136f760101cce8bd38ba4fdd4c7388c7a060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [1.9.4](https://forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/compare/v1.9.3...v1.9.4) (2022-05-18) + + +### Features + +* **profileType:** invert month and year fields ([be836f9](https://forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/commit/be836f9d5e4ff07e5c56175d932aa753515a0c1b)) + + +### Bug Fixes + +* **ecogestures:** Update ecogesture profile and profiletype properly ([5f2d053](https://forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/commit/5f2d0535ee5103c5b76a0446c11f399e1c9a682e)) + ### [1.9.3](https://forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/compare/v1.9.2...v1.9.3) (2022-05-10) ### Bug Fixes diff --git a/manifest.webapp b/manifest.webapp index a824ec250f9bc387300dd5dfbfe62e9a0043fb40..079a72070b0abed84ee4c82b81f485cbfe10f664 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -3,7 +3,7 @@ "slug": "ecolyo", "icon": "icon.svg", "categories": ["energy"], - "version": "1.9.3", + "version": "1.9.4", "licence": "AGPL-3.0", "editor": "Métropole de Lyon", "default_locale": "fr", diff --git a/package.json b/package.json index a93d4328cb275dd5f907948a086bfa909113c8f2..c4308dd99314ddf16f653175cb9b3b527d014012 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ecolyo", - "version": "1.9.3", + "version": "1.9.4", "scripts": { "tx": "tx pull --all || true", "lint": "yarn lint:js && yarn lint:styles", diff --git a/src/components/EcogestureForm/EcogestureFormEquipment.tsx b/src/components/EcogestureForm/EcogestureFormEquipment.tsx index 857f575a6383a374013fd4145c76611ee1317532..8f0524dbd29ef957a45f40723e1ccb4903861424 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment.tsx @@ -7,7 +7,10 @@ import { ProfileEcogesture } from 'models/profileEcogesture.model' import { EquipmentType } from 'enum/ecogesture.enum' import EquipmentIcon from './EquipmentIcon' import './ecogestureFormEquipment.scss' -import { newProfileEcogestureEntry } from 'store/profileEcogesture/profileEcogesture.actions' +import { + newProfileEcogestureEntry, + updateProfileEcogesture, +} from 'store/profileEcogesture/profileEcogesture.actions' import { useDispatch, useSelector } from 'react-redux' import { updateProfile } from 'store/profile/profile.actions' import { useHistory } from 'react-router-dom' @@ -43,11 +46,12 @@ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({ const handleNext = useCallback(() => { profileEcogesture.equipments = answer as EquipmentType[] - dispatch(newProfileEcogestureEntry(profileEcogesture)) // Check if gestureForm is used from Big profile or small profile if (setNextStep) { setNextStep() + dispatch(updateProfileEcogesture(profileEcogesture)) } else { + dispatch(newProfileEcogestureEntry(profileEcogesture)) dispatch(updateProfile({ isProfileEcogestureCompleted: true })) history.push('/ecogesture-selection') } diff --git a/src/components/EcogestureForm/EcogestureFormView.tsx b/src/components/EcogestureForm/EcogestureFormView.tsx index 18812975d292be79358555e9dd838169b6e434ae..cb07519ce15b54b21fb914f1e883c49c65011351 100644 --- a/src/components/EcogestureForm/EcogestureFormView.tsx +++ b/src/components/EcogestureForm/EcogestureFormView.tsx @@ -20,11 +20,10 @@ import ProfileEcogestureFormService from 'services/profileEcogestureForm.service import StyledSpinner from 'components/CommonKit/Spinner/StyledSpinner' import { FluidType } from 'enum/fluid.enum' import './ecogestureFormView.scss' -import { useHistory, useLocation } from 'react-router-dom' +import { useLocation } from 'react-router-dom' import ProfileTypeView from 'components/ProfileType/ProfileTypeView' const EcogestureFormView: React.FC = () => { - const history = useHistory() const [headerHeight, setHeaderHeight] = useState<number>(0) const defineHeaderHeight = (height: number) => { setHeaderHeight(height) @@ -111,9 +110,7 @@ const EcogestureFormView: React.FC = () => { ></Header> <Content height={headerHeight}> {isProfileTypeCompleted ? ( - <ProfileTypeView - handleEnd={() => history.push('/ecogesture-selection')} - /> + <ProfileTypeView /> ) : ( <> {step === EcogestureStepForm.EQUIPMENTS && ( diff --git a/src/components/ProfileType/ProfileTypeFinished.spec.tsx b/src/components/ProfileType/ProfileTypeFinished.spec.tsx index 5500282f8580a31156513f7f51cd4f14d101115d..60f540a189cae15d509f1f49d466241cf8dc1b3a 100644 --- a/src/components/ProfileType/ProfileTypeFinished.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFinished.spec.tsx @@ -7,7 +7,21 @@ import { } from '../../../tests/__mocks__/store' import ProfileTypeFinished from './ProfileTypeFinished' import { mockProfileType } from '../../../tests/__mocks__/profileType.mock' +import { Button } from '@material-ui/core' +const mockHistoryGoBack = jest.fn() +const mockHistoryPush = jest.fn() + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useLocation: () => ({ + pathname: '/ecogesture-form', + }), + useHistory: () => ({ + goBack: mockHistoryGoBack, + push: mockHistoryPush, + }), +})) jest.mock('cozy-ui/transpiled/react/I18n', () => { return { useI18n: jest.fn(() => { @@ -18,14 +32,18 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) -describe('ProfileTypeView component', () => { +describe('ProfileTypeFinished component', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let store: any beforeEach(() => { + jest.clearAllMocks() store = createMockStore(mockInitialEcolyoState) }) + afterEach(() => { + jest.clearAllMocks() + }) - it('should be rendered correctly', () => { + it('should be rendered correctly', async () => { const wrapper = mount( <Provider store={store}> <ProfileTypeFinished profileType={mockProfileType} /> @@ -33,4 +51,16 @@ describe('ProfileTypeView component', () => { ) expect(wrapper.find('profile-type-finished-card')).toBeTruthy() }) + it('should go to ecogesture selection', () => { + const wrapper = mount( + <Provider store={store}> + <ProfileTypeFinished profileType={mockProfileType} /> + </Provider> + ) + wrapper + .find(Button) + .first() + .simulate('click') + expect(mockHistoryPush).toHaveBeenCalledWith('/ecogesture-selection') + }) }) diff --git a/src/components/ProfileType/ProfileTypeFinished.tsx b/src/components/ProfileType/ProfileTypeFinished.tsx index 714438c7fd798ead16b92fbcb12c4a4516e94e3d..be6a82b0c28f9351c09d2526f2240e8cef9e9ae1 100644 --- a/src/components/ProfileType/ProfileTypeFinished.tsx +++ b/src/components/ProfileType/ProfileTypeFinished.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react' import 'components/ProfileType/profileTypeFinished.scss' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useDispatch, useSelector } from 'react-redux' -import { useHistory } from 'react-router-dom' +import { useHistory, useLocation } from 'react-router-dom' import { updateProfile } from 'store/profile/profile.actions' import { newProfileTypeEntry } from 'store/profileType/profileType.actions' import { ProfileType } from 'models/profileType.model' @@ -28,6 +28,7 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ profileType, }: ProfileTypeFinishedProps) => { const { t } = useI18n() + const location = useLocation() const dispatch = useDispatch() const history = useHistory() const client = useClient() @@ -35,7 +36,11 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ (state: AppStore) => state.ecolyo.challenge ) const handleClick = () => { - history.goBack() + if (location && location.pathname === '/ecogesture-form') { + history.push('/ecogesture-selection') + } else { + history.goBack() + } } const [isSaved, setIsSaved] = useState<boolean>(false) diff --git a/src/components/ProfileType/ProfileTypeFormDateSelection.tsx b/src/components/ProfileType/ProfileTypeFormDateSelection.tsx index 693413cf5e7d27b8f4d328acca88770c720910b0..05b3b77afb774d9bae601360d4f3ee7f88c974e5 100644 --- a/src/components/ProfileType/ProfileTypeFormDateSelection.tsx +++ b/src/components/ProfileType/ProfileTypeFormDateSelection.tsx @@ -189,6 +189,20 @@ const ProfileTypeFormDateSelection: React.FC<ProfileTypeFormDateSelectionProps> </div> {answer !== null ? ( <div className="select-container"> + <div className="date-select"> + <Select + labelId="selectYearDate" + className="year" + defaultValue={selectedYear} + onChange={e => handleSelectYear(e)} + > + {selectYears.map((year, key) => ( + <MenuItem value={year} key={key} className="date-option"> + {year} + </MenuItem> + ))} + </Select> + </div> <div className="date-select"> <Select native={false} @@ -221,20 +235,6 @@ const ProfileTypeFormDateSelection: React.FC<ProfileTypeFormDateSelectionProps> ))} </Select> </div> - <div className="date-select"> - <Select - labelId="selectYearDate" - className="year" - defaultValue={selectedYear} - onChange={e => handleSelectYear(e)} - > - {selectYears.map((year, key) => ( - <MenuItem value={year} key={key} className="date-option"> - {year} - </MenuItem> - ))} - </Select> - </div> </div> ) : null} </div> diff --git a/src/components/ProfileType/ProfileTypeView.tsx b/src/components/ProfileType/ProfileTypeView.tsx index 40bfbdef84d4997c2daa6d9836fd305039685c3c..8d43c4f1f7d9fd414e75fe17013e87be23ce6bcb 100644 --- a/src/components/ProfileType/ProfileTypeView.tsx +++ b/src/components/ProfileType/ProfileTypeView.tsx @@ -32,13 +32,7 @@ import ProfileTypeFormDateSelection from './ProfileTypeFormDateSelection' import EcogestureFormEquipment from 'components/EcogestureForm/EcogestureFormEquipment' import { ProfileEcogesture } from 'models/profileEcogesture.model' -interface ProfileTypeViewProps { - handleEnd: Function -} - -const ProfileTypeView: React.FC<ProfileTypeViewProps> = ({ - handleEnd, -}: ProfileTypeViewProps) => { +const ProfileTypeView: React.FC = () => { const profile = useSelector((state: AppStore) => state.ecolyo.profile) const curProfileType = useSelector( (state: AppStore) => state.ecolyo.profileType @@ -107,9 +101,6 @@ const ProfileTypeView: React.FC<ProfileTypeViewProps> = ({ step, !profile.isProfileTypeCompleted ) - if (nextStep === ProfileTypeStepForm.END && handleEnd) { - handleEnd() - } setIsLoading(true) if (nextStep > viewedStep) { setViewedStep(nextStep) @@ -118,7 +109,6 @@ const ProfileTypeView: React.FC<ProfileTypeViewProps> = ({ }, [ curProfileEcogesture, - handleEnd, profile.isProfileTypeCompleted, profileType, step, diff --git a/src/styles/index.css b/src/styles/index.css index 9e1b70aab157ae4e9f6c485cc9310d15b259c173..f6c38b90351ff7c47bba17d78ceddf621c575ef5 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -6,6 +6,7 @@ /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -172,6 +173,7 @@ body { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -182,6 +184,7 @@ body { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -651,6 +654,7 @@ p { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -941,6 +945,7 @@ p { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1160,6 +1165,7 @@ button.btn-profile-back { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1185,6 +1191,7 @@ button.btn-profile-back { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1260,6 +1267,7 @@ div.modal-paper-full-screen { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1324,6 +1332,7 @@ div.expansion-panel-details { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/