From fb46af530d65b4ec83ae569d74d820582c698533 Mon Sep 17 00:00:00 2001 From: CARRON Guilhem <guilhem.carron@soprasteria.com> Date: Mon, 20 Jul 2020 10:23:39 +0200 Subject: [PATCH] add translation + change enrgyRecap to Report --- .../ViewContainer/ProfileViewContainer.tsx | 4 +-- .../ViewContainer/ViewContainer.tsx | 13 +------- .../EnergyRecap.tsx => Report/Report.tsx} | 32 ++++++++----------- src/locales/fr.json | 8 +++++ src/services/dataChallengeContracts.ts | 6 ++-- 5 files changed, 28 insertions(+), 35 deletions(-) rename src/components/ContentComponents/{EnergyRecap/EnergyRecap.tsx => Report/Report.tsx} (67%) diff --git a/src/components/ContainerComponents/ViewContainer/ProfileViewContainer.tsx b/src/components/ContainerComponents/ViewContainer/ProfileViewContainer.tsx index 040d30589..e6aceefc3 100644 --- a/src/components/ContainerComponents/ViewContainer/ProfileViewContainer.tsx +++ b/src/components/ContainerComponents/ViewContainer/ProfileViewContainer.tsx @@ -3,7 +3,7 @@ import CozyBar from 'components/ContainerComponents/CozyBar/CozyBar' import Header from 'components/ContainerComponents/Header/Header' import Content from 'components/ContainerComponents/Content/Content' import KonnectorViewerContainer from 'components/ContainerComponents/KonnectorViewerContainer/KonnectorViewerContainer' -import EnergyRecap from 'components/ContentComponents/EnergyRecap/EnergyRecap' +import Report from 'components/ContentComponents/Report/Report' const ProfileViewContainer: React.FC = () => { const [headerHeight, setHeaderHeight] = useState<number>(0) @@ -18,7 +18,7 @@ const ProfileViewContainer: React.FC = () => { desktopTitleKey={'COMMON.APP_PARAMETERS_TITLE'} ></Header> <Content height={headerHeight}> - <EnergyRecap /> + <Report /> <KonnectorViewerContainer isParam={true} /> </Content> </> diff --git a/src/components/ContainerComponents/ViewContainer/ViewContainer.tsx b/src/components/ContainerComponents/ViewContainer/ViewContainer.tsx index 9ddce6b16..cf4ac4cc8 100644 --- a/src/components/ContainerComponents/ViewContainer/ViewContainer.tsx +++ b/src/components/ContainerComponents/ViewContainer/ViewContainer.tsx @@ -119,18 +119,7 @@ export const ViewContainer = () => { </> )} /> - <Route - path="/profile" - render={({ match: { url } }) => ( - <> - <Route - path={`${url}/`} - component={ProfileViewContainer} - exact - /> - </> - )} - /> + <Route path="/profile" component={ProfileViewContainer} /> <Route path="/splash" component={SplashContainer} /> <Redirect from="/" to="/consumption" /> <Redirect from="*" to="/consumption" /> diff --git a/src/components/ContentComponents/EnergyRecap/EnergyRecap.tsx b/src/components/ContentComponents/Report/Report.tsx similarity index 67% rename from src/components/ContentComponents/EnergyRecap/EnergyRecap.tsx rename to src/components/ContentComponents/Report/Report.tsx index c20f14694..838085ffe 100644 --- a/src/components/ContentComponents/EnergyRecap/EnergyRecap.tsx +++ b/src/components/ContentComponents/Report/Report.tsx @@ -4,75 +4,71 @@ import { AppContext } from 'components/Contexts/AppContextProvider' import UserProfileManager from 'services/userProfileDataManagerService' import { Client, withClient } from 'cozy-client' -interface EnergyRecapProps { +interface ReportProps { t: Function client: Client } -const EnergyRecap: React.FC<EnergyRecapProps> = ({ - t, - client, -}: EnergyRecapProps) => { +const Report: React.FC<ReportProps> = ({ t, client }: ReportProps) => { const [state, setstate] = useState<string>('') const { userProfile } = useContext(AppContext) const upm = new UserProfileManager(client) const updatedUserProfile = async (value: string) => { - return await upm.updateUserProfile({ energyBilanRecap: value }) + return await upm.updateUserProfile({ report: value }) } useEffect(() => { - if (userProfile && userProfile.energyBilanRecap) - setstate(userProfile.energyBilanRecap) + if (userProfile && userProfile.report) setstate(userProfile.report) }, []) - const handleChange = (e: any) => { + const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { updatedUserProfile(e.target.value).then(data => { - if (data) setstate(data.energyBilanRecap) + if (data) setstate(data.report) }) } return ( <div className="energy-recap-container"> <div className="head text-14-normal-uppercase"> - Réception du bilan énergétique + {t('PROFILE.REPORT.TITLE')} </div> <form action="" className="radios"> <div className="input"> <input id="weekly" - name="energyBilanRecap" + name="report" type="radio" value="weekly" onChange={handleChange} checked={state === 'weekly'} ></input> - <label htmlFor="weekly">Hebdomadaire</label> + <label htmlFor="weekly"> {t('PROFILE.REPORT.WEEKLY')}</label> </div> <div className="input"> <input id="monthly" - name="energyBilanRecap" + name="report" type="radio" value="monthly" onChange={handleChange} checked={state === 'monthly'} ></input> - <label htmlFor="monthly">Mensuel</label> + <label htmlFor="monthly"> {t('PROFILE.REPORT.MONTHLY')}</label> </div> <div className="input"> <input id="never" - name="energyBilanRecap" + name="report" type="radio" value="never" onChange={handleChange} checked={state === 'never'} ></input> - <label htmlFor="never">Jamais</label> + <label htmlFor="never"> {t('PROFILE.REPORT.NEVER')}</label> </div> </form> </div> ) } -export default translate()(withClient(EnergyRecap)) +export default translate()(withClient(Report)) diff --git a/src/locales/fr.json b/src/locales/fr.json index c6e571202..e063790cb 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -110,6 +110,14 @@ "DISPLAY_DETAIL": "Voir le détail", "DISPLAY_LAST_DATA": "Voir mes dernières consos" }, + "PROFILE": { + "REPORT": { + "TITLE": "Réception du bilan énergétique", + "WEEKLY": "Hebdomadaire", + "MONTHLY": "Mensuel", + "NEVER": "Jamais" + } + }, "KONNECTORCONFIG": { "TITLE_CONNECTION": "Connexion aux distributeurs", "TITLE_KONNECTEURS": "connecteurs", diff --git a/src/services/dataChallengeContracts.ts b/src/services/dataChallengeContracts.ts index 3c6471adc..61b0ee344 100644 --- a/src/services/dataChallengeContracts.ts +++ b/src/services/dataChallengeContracts.ts @@ -141,7 +141,7 @@ export class UserProfile { challengeTypeHash: string ecogestureHash: string haveSeenWelcomeModal: boolean - energyBilanRecap: string + report: string constructor( id: string, @@ -149,14 +149,14 @@ export class UserProfile { challengeTypeHash: string, ecogestureHash: string, haveSeenWelcomeModal: boolean, - energyBilanRecap: string + report: string ) { this.id = id this.level = level this.challengeTypeHash = challengeTypeHash this.ecogestureHash = ecogestureHash this.haveSeenWelcomeModal = haveSeenWelcomeModal - this.energyBilanRecap = energyBilanRecap + this.report = report } } -- GitLab