Skip to content
Snippets Groups Projects
Commit bfe6a76b authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

wip: modal ok, écrous à afficher sur les konnector

parent 475ec2f7
No related branches found
No related tags found
1 merge request!497Feat/us555 partners check
Showing with 249 additions and 4 deletions
<svg width="26" height="26" viewBox="0 0 26 26" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_9986_55791)">
<circle cx="13" cy="11" r="11" fill="#383941"/>
<circle cx="13" cy="11" r="10.5" stroke="white"/>
</g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M19 11.7213V10.2471H17.4414C17.3295 9.5783 17.0672 8.94367 16.6741 8.39114L17.7757 7.28962L16.711 6.225L15.6094 7.32652C15.0568 6.93317 14.4222 6.67033 13.7533 6.55779V5H12.2474V6.55779C11.5784 6.66998 10.9437 6.93285 10.3914 7.32652L9.28977 6.225L8.24691 7.26703L9.34549 8.36554C8.94176 8.92382 8.67224 9.56769 8.55788 10.2471H7V11.7213H8.55337C8.66213 12.4016 8.92651 13.0475 9.32591 13.6089L8.22432 14.7104L9.28901 15.775L10.3906 14.6735C10.9327 15.0597 11.563 15.3263 12.2467 15.4422V17H13.7526V15.4422C14.432 15.3277 15.0759 15.0582 15.6342 14.6547L16.7321 15.7524L17.7749 14.7104L16.6733 13.6089C17.0726 13.0474 17.3369 12.4015 17.4459 11.7213H19ZM13.0154 13.2972C12.41 13.2817 11.8345 13.0304 11.4118 12.5968C10.989 12.1631 10.7524 11.5815 10.7524 10.9759C10.7524 10.3703 10.989 9.78868 11.4118 9.35505C11.8345 8.92141 12.41 8.67008 13.0154 8.65466C13.6209 8.67008 14.1963 8.92141 14.6191 9.35505C15.0418 9.78868 15.2784 10.3703 15.2784 10.9759C15.2784 11.5815 15.0418 12.1631 14.6191 12.5968C14.1963 13.0304 13.6209 13.2817 13.0154 13.2972Z" fill="white"/>
<defs>
<filter id="filter0_d_9986_55791" x="0" y="0" width="26" height="26" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset dy="2"/>
<feGaussianBlur stdDeviation="1"/>
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_9986_55791"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_9986_55791" result="shape"/>
</filter>
</defs>
</svg>
......@@ -20,6 +20,7 @@ import classNames from 'classnames'
import { isKonnectorActive } from 'utils/utils'
import ReleaseNotesModal from './releaseNotesModal'
import { showReleaseNotes } from 'store/global/global.actions'
import PartnersIssueModal from 'components/PartnersIssue/PartnersIssueModal'
interface ConsumptionViewProps {
fluidType: FluidType
......@@ -31,9 +32,12 @@ const ConsumptionView: React.FC<ConsumptionViewProps> = ({
const { currentTimeStep, loading } = useSelector(
(state: AppStore) => state.ecolyo.chart
)
const { fluidStatus, releaseNotes } = useSelector(
(state: AppStore) => state.ecolyo.global
)
const {
fluidStatus,
releaseNotes,
openPartnersIssueModal,
partnersIssueMessage,
} = useSelector((state: AppStore) => state.ecolyo.global)
const [isFluidKonnected, setIsFluidKonnected] = useState<boolean>(false)
const [openReleaseNoteModal, setOpenReleaseNoteModal] = useState<boolean>(
......@@ -139,6 +143,14 @@ const ConsumptionView: React.FC<ConsumptionViewProps> = ({
</div>
)}
</Content>
<PartnersIssueModal
message={partnersIssueMessage}
open={openPartnersIssueModal}
handleCloseClick={function(): void {
throw new Error('Function not implemented.')
}}
/>
</>
)
}
......
import React from 'react'
import './partnersIssueModal.scss'
import Button from '@material-ui/core/Button'
import Dialog from '@material-ui/core/Dialog'
interface PartnersIssueModalProps {
message: string
open: boolean
handleCloseClick: () => void
}
const PartnersIssueModal: React.FC<PartnersIssueModalProps> = ({
message,
open,
handleCloseClick,
}: PartnersIssueModalProps) => {
return (
<Dialog
open={open}
disableBackdropClick
disableEscapeKeyDown
onClose={handleCloseClick}
aria-labelledby={'accessibility-title'}
classes={{
root: 'modal-root',
paper: 'modal-paper',
}}
>
<div className="partnersIssueModal">
<div className="partners-issue-title">Problèmes partenaires</div>
<div className="partners-issue-content">{{ message }}</div>
<Button
onClick={handleCloseClick}
classes={{
root: 'btn-secondary-negative',
label: 'text-16-normal',
}}
>
OK
</Button>
</div>
</Dialog>
)
}
export default PartnersIssueModal
@import '../../styles/base/typo-variables';
.partnersIssueModal {
padding: 1rem;
max-width: 20rem;
.partners-issue-title {
text-transform: uppercase;
font-size: 1.8rem;
color: white;
font-family: $text-font;
margin: 0.5rem auto;
text-align: center;
}
.partners-issue-content {
font-size: 1.1rem;
color: white;
font-family: $text-font;
text-align: center;
}
button.btn-secondary-negative {
display: block;
text-align: center;
margin: auto;
margin-top: 3.5rem;
margin-bottom: 0;
}
}
.partners-issue-portal {
.modal-overlay {
.modal-box {
max-width: 21rem;
}
}
}
#accessibility-title {
display: none;
}
......@@ -8,6 +8,8 @@ import React, {
import { useClient } from 'cozy-client'
import classNames from 'classnames'
import { useDispatch } from 'react-redux'
import { FluidState, FluidType } from 'enum/fluid.enum'
import {
toggleAnalysisNotification,
toggleChallengeExplorationNotification,
......@@ -17,6 +19,7 @@ import {
GlobalActionTypes,
updateTermValidation,
showReleaseNotes,
SetPartnersIssue,
} from 'store/global/global.actions'
import {
ProfileActionTypes,
......@@ -46,12 +49,14 @@ import {
import { DateTime } from 'luxon'
import { UserActionState } from 'enum/userAction.enum'
import ActionService from 'services/action.service'
import { UserChallenge } from 'models'
import { FluidStatus, UserChallenge } from 'models'
import UsageEventService from 'services/usageEvent.service'
import { UsageEventType } from 'enum/usageEvent.enum'
import { MigrationService } from 'migrations/migration.service'
import { migrations } from 'migrations/migration.data'
import { ReleaseNotes } from 'models/releaseNotes.model'
import PartnersInfoService from 'services/partnersInfo.service'
import FluidService from 'services/fluid.service'
interface SplashRootProps {
fadeTimer?: number
......@@ -100,6 +105,7 @@ const SplashRoot = ({
let subscribed = true
async function loadData() {
const initializationService = new InitializationService(client)
const partnersInfoService = new PartnersInfoService(client)
const ms = new MigrationService(client)
const migrationsResult: ReleaseNotes = await ms.runMigrations(migrations)
try {
......@@ -242,6 +248,45 @@ const SplashRoot = ({
...prev,
splashStart: true,
}))
// Check partnersInfo from backoffice
const partnersInfo = await partnersInfoService.getPartnersInfo()
// Get last partnerIssueDate
profile && profile.partnerIssueDate
const today = DateTime.local().startOf('day')
if (
partnersInfo.notification_activated &&
today !== (profile && profile.partnerIssueDate)
) {
const fluidService = new FluidService(client)
const _updatedFluidStatus: FluidStatus[] = await fluidService.getFluidStatus()
for (const fluid of _updatedFluidStatus) {
if (
partnersInfo.grdf_failure &&
fluid.fluidType === FluidType.GAS
) {
fluid.status = FluidState.PARTNER_ISSUE
}
if (
partnersInfo.enedis_failure &&
fluid.fluidType === FluidType.ELECTRICITY
) {
fluid.status = FluidState.PARTNER_ISSUE
}
if (
partnersInfo.egl_failure &&
fluid.fluidType === FluidType.WATER
) {
fluid.status = FluidState.PARTNER_ISSUE
}
}
dispatch(setFluidStatus(_updatedFluidStatus))
dispatch(SetPartnersIssue(true, partnersInfo.message))
console.log('AFFICHER POP-UP')
} else {
}
} catch (err) {
setError(err)
}
......
......@@ -11,4 +11,5 @@ export enum FluidState {
DONE = 200,
ERROR = 300,
ERROR_LOGIN_FAILED = 301,
PARTNER_ISSUE = 500,
}
......@@ -264,4 +264,22 @@ export const migrations: Migration[] = [
return docs
},
},
{
baseSchemaVersion: 8,
targetSchemaVersion: 9,
appVersion: '1.6.0',
description:
"Profil nows contains partnerIssueDate in order to handle partners' issue display",
releaseNotes: null,
docTypes: PROFILE_DOCTYPE,
run: async (_client: Client, docs: any[]): Promise<Profile[]> => {
return docs.map((doc: Profile) => {
doc.partnerIssueDate = DateTime.local()
.minus({ day: 1 })
.startOf('day')
console.log(doc)
return doc
})
},
},
]
......@@ -161,6 +161,7 @@ export async function migrate(
break
}
} catch (err) {
console.error(err)
result = {
type: MIGRATION_RESULT_FAILED,
errors: [err.toString()],
......
......@@ -13,4 +13,6 @@ export interface GlobalState {
isLastTermAccepted: boolean
fluidStatus: FluidStatus[]
fluidTypes: FluidType[]
openPartnersIssueModal: boolean
partnersIssueMessage: string
}
export interface PartnersInfo {
message: string
grdf_failure: boolean
enedis_failure: boolean
egl_failure: boolean
notification_activated: boolean
}
......@@ -23,6 +23,7 @@ export interface ProfileEntity {
mailToken: string
_id?: string
_rev?: string
partnerIssueDate: DateTime
}
export interface Profile
......
import { Client } from 'cozy-client'
import { PartnersInfo } from 'models/partnersInfo.model'
export default class PartnersInfoService {
private readonly _client: Client
constructor(_client: Client) {
this._client = _client
}
/*
* Get information from backoffice about the status of partners' service
* On success, respond the partnersInfo
* Else, throw an error
*/
public async getPartnersInfo(): Promise<PartnersInfo> {
try {
const result = await this._client
.getStackClient()
.fetchJSON('GET', '/remote/org.ecolyo.backoffice.partners.info.rec')
return result as PartnersInfo
} catch (error) {
console.error(error)
throw new Error("Failed to get partners' info")
}
}
}
......@@ -15,6 +15,7 @@ export const TOGGLE_ANALYSIS_NOTIFICATION = 'TOGGLE_ANALYSIS_NOTIFICATION'
export const SET_FLUID_STATUS = 'SET_FLUID_STATUS'
export const UPDATE_FLUID_CONNECTION = 'UPDATE_FLUID_CONNECTION'
export const UPDATE_TERMS_VALIDATION = 'UPDATE_TERMS_VALIDATION'
export const SET_PARTNERS_ISSUE = 'SET_PARTNERS_ISSUE'
interface ChangeScreenType {
type: typeof CHANGE_SCREEN_TYPE
......@@ -61,6 +62,11 @@ interface ShowReleaseNotes {
payload?: { show: boolean; notes: Notes[] }
}
interface SetPartnersIssue {
type: typeof SET_PARTNERS_ISSUE
payload?: { openPartnersIssueModal: boolean; partnersIssueMessage: string }
}
export type GlobalActionTypes =
| ChangeScreenType
| ToogleChallengeExplorationNotification
......@@ -71,6 +77,7 @@ export type GlobalActionTypes =
| UpdatedFluidConnection
| UpdateTermValidation
| ShowReleaseNotes
| SetPartnersIssue
export function changeScreenType(screenType: ScreenType): GlobalActionTypes {
return {
......@@ -147,3 +154,13 @@ export function updateTermValidation(
payload: isLastTermAccepted,
}
}
export function SetPartnersIssue(
openPartnersIssueModal: boolean,
partnersIssueMessage: string
): GlobalActionTypes {
return {
type: SET_PARTNERS_ISSUE,
payload: { openPartnersIssueModal, partnersIssueMessage },
}
}
......@@ -10,6 +10,7 @@ import {
GlobalActionTypes,
UPDATE_TERMS_VALIDATION,
SHOW_RELEASE_NOTES,
SET_PARTNERS_ISSUE,
} from 'store/global/global.actions'
import { FluidStatus, GlobalState } from 'models'
import { ScreenType } from 'enum/screen.enum'
......@@ -94,6 +95,8 @@ const initialState: GlobalState = {
},
],
fluidTypes: [],
openPartnersIssueModal: false,
partnersIssueMessage: '',
}
const getFluidTypesFromStatus = (fluidStatus: FluidStatus[]): FluidType[] => {
......@@ -172,6 +175,14 @@ export const globalReducer: Reducer<GlobalState> = (
releaseNotes: action.payload,
}
: state
case SET_PARTNERS_ISSUE:
return action.payload != undefined
? {
...state,
openPartnersIssueModal: action.payload.openPartnersIssueModal,
partnersIssueMessage: action.payload.partnersIssueMessage,
}
: state
case UPDATE_FLUID_CONNECTION:
if (action.payload !== undefined) {
const updatedFluidStatus = [...state.fluidStatus]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment