diff --git a/src/components/Connection/ConnectionOAuth.tsx b/src/components/Connection/ConnectionOAuth.tsx index 28ae7b3557d8654bfc0f7c5a9512c9e36b9bde76..1bd69c164cb941b594abd1c27f3b3a15833904af 100644 --- a/src/components/Connection/ConnectionOAuth.tsx +++ b/src/components/Connection/ConnectionOAuth.tsx @@ -86,7 +86,7 @@ const ConnectionOAuth: React.FC<ConnectionOAuthProps> = ({ ) const togglePartnerConnectionModal = useCallback(() => { - setOpenPartenerConnectionModal(prev => !prev) + setOpenPartenerConnectionModal((prev: boolean) => !prev) }, []) const handleEndSteps = useCallback(() => { diff --git a/src/components/Connection/ConnectionOAuthNoPartnerAccount.tsx b/src/components/Connection/ConnectionOAuthNoPartnerAccount.tsx index d58a27ef47410fa1276dfdc823513473678e17ce..807e20753cba4ee1412dc81bde39d8d9310f3501 100644 --- a/src/components/Connection/ConnectionOAuthNoPartnerAccount.tsx +++ b/src/components/Connection/ConnectionOAuthNoPartnerAccount.tsx @@ -2,7 +2,7 @@ import React from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import './connectionOAuth.scss' import { Konnector } from 'models' -import OAuthForm from 'components/Connection/FormOAuth' +import FormOAuth from 'components/Connection/FormOAuth' import Button from '@material-ui/core/Button' interface ConnectionOAuthNoPartnerAccountProps { @@ -49,7 +49,7 @@ const ConnectionOAuthNoPartnerAccount = ({ {t('auth.' + `${konnectorSlug}` + '.no_account.subtitle2_info')} </div> <div className="koauthform-connect-button"> - <OAuthForm + <FormOAuth konnector={konnector} onSuccess={handleSuccess} highlightedStyle={false} diff --git a/src/components/Connection/ConnectionOAuthWithPartnerAccount.tsx b/src/components/Connection/ConnectionOAuthWithPartnerAccount.tsx index 659b3c27b2e3fa4e4b499b0f17cde1b32f7ff067..c0d9bbb26e0101afbc6b82ef23b917fcc4a54185 100644 --- a/src/components/Connection/ConnectionOAuthWithPartnerAccount.tsx +++ b/src/components/Connection/ConnectionOAuthWithPartnerAccount.tsx @@ -2,7 +2,7 @@ import React, { useCallback } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import './connectionOAuth.scss' import { Konnector } from 'models' -import OAuthForm from 'components/Connection/FormOAuth' +import FormOAuth from 'components/Connection/FormOAuth' import Button from '@material-ui/core/Button' interface ConnectionOAuthWithPartnerAccountProps { @@ -37,7 +37,7 @@ const ConnectionOAuthWithPartnerAccount = ({ {t('auth.' + konnectorSlug + '.with_account.subtitle1')} </div> <div className="koauthform-connect-button"> - <OAuthForm + <FormOAuth konnector={konnector} onSuccess={handleSuccess} highlightedStyle={true} diff --git a/src/components/Connection/FormOAuth.tsx b/src/components/Connection/FormOAuth.tsx index 85843b5a6fe4395b25ebe13baa62aab09ef14c1e..f781844b7c25fc9f3fc2b2f3451b99382c423bca 100644 --- a/src/components/Connection/FormOAuth.tsx +++ b/src/components/Connection/FormOAuth.tsx @@ -27,25 +27,25 @@ const FormOAuth: React.FC<FormOAuthProps> = ({ const client = useClient() const [status, setStatus] = useState<string>(IDLE) - const endOAuth = () => { + const endOAuth = useCallback(() => { setStatus(IDLE) - } - const startOAuth = () => { + }, []) + + const startOAuth = useCallback(() => { setStatus(WAITING) - } + }, []) + const handleAccountId = useCallback( (accountId: string) => { endOAuth() onSuccess(accountId) }, - [onSuccess] + [endOAuth, onSuccess] ) - const handleSubmit = () => { - startOAuth() - } + const handleOAuthCancel = useCallback(() => { endOAuth() - }, []) + }, [endOAuth]) const icon = getPartnerPicto( konnector ? konnector.slug : '', @@ -60,7 +60,7 @@ const FormOAuth: React.FC<FormOAuthProps> = ({ <> <Button aria-label={t('auth.accessibility.button_connect')} - onClick={handleSubmit} + onClick={startOAuth} disabled={isWaiting} classes={{ root: `${ diff --git a/src/migrations/migration.data.ts b/src/migrations/migration.data.ts index ec04ee6863c226d716272df3c9bda547ec7ce7a5..8671b69e5c4c71039891922268e0307655aa71ee 100644 --- a/src/migrations/migration.data.ts +++ b/src/migrations/migration.data.ts @@ -7,8 +7,10 @@ import { EGL_MONTH_DOCTYPE, EGL_YEAR_DOCTYPE, FLUIDPRICES_DOCTYPE, + ENEDIS_DAY_DOCTYPE, + GRDF_DAY_DOCTYPE, } from 'doctypes' -import { Profile, ProfileType, UserChallenge } from 'models' +import { DataloadEntity, Profile, ProfileType, UserChallenge } from 'models' import { Client } from 'cozy-client' import { DateTime } from 'luxon' import { UserQuizState } from 'enum/userQuiz.enum' @@ -319,4 +321,80 @@ export const migrations: Migration[] = [ }) }, }, + { + baseSchemaVersion: 11, + targetSchemaVersion: 12, + appVersion: '1.6.1', + description: 'Corrects daily Enedis data.', + releaseNotes: null, + docTypes: ENEDIS_DAY_DOCTYPE, + queryOptions: { + scope: 'conso', + tag: 'day', + limit: 730, + }, + run: async (_client: Client, docs: any[]): Promise<DataloadEntity[]> => { + let prevData: DataloadEntity = { + id: '', + day: 0, + hour: 0, + load: 0, + minute: 0, + month: 0, + year: 0, + } + return docs.map(doc => { + if ( + prevData.day === doc.day && + prevData.month === doc.month && + prevData.year === doc.year + ) { + doc.deleteAction = true + } + if (doc.price) { + delete doc.price + } + prevData = doc + return doc + }) + }, + }, + { + baseSchemaVersion: 12, + targetSchemaVersion: 13, + appVersion: '1.6.1', + description: 'Corrects daily GRDF data.', + releaseNotes: null, + docTypes: GRDF_DAY_DOCTYPE, + queryOptions: { + scope: 'conso', + tag: 'day', + limit: 730, + }, + run: async (_client: Client, docs: any[]): Promise<DataloadEntity[]> => { + let prevData: DataloadEntity = { + id: '', + day: 0, + hour: 0, + load: 0, + minute: 0, + month: 0, + year: 0, + } + return docs.map(doc => { + if ( + prevData.day === doc.day && + prevData.month === doc.month && + prevData.year === doc.year + ) { + doc.deleteAction = true + } + if (doc.price) { + delete doc.price + } + prevData = doc + return doc + }) + }, + }, ]