Newer
Older
import { Button } from '@material-ui/core'
import { useClient } from 'cozy-client'
import React, { Dispatch, useCallback, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { decoreText } from 'utils/decoreText'
import DataShareConsentContent from './DataShareConsentContent'
import LegalNoticeModal from './LegalNoticeModal'
import MinorUpdateContent from './MinorUpdateContent'
import './termsView.scss'
const dispatch = useDispatch<Dispatch<AppActionsTypes>>()
const navigate = useNavigate()
const [dataConsentValidation, setDataConsentValidation] =
useState<boolean>(false)
const [openCGUModal, setOpenCGUModal] = useState<boolean>(false)
const [openLegalNoticeModal, setOpenLegalNoticeModal] =
useState<boolean>(false)
const { termsStatus } = useSelector((state: AppStore) => state.ecolyo.global)
const toggleCGUModal = () => {
setOpenCGUModal(prev => !prev)
}
const toggleLegalNoticeModal = () => {
setOpenLegalNoticeModal(prev => !prev)
}
const handleGCUValidate = useCallback(() => {
setGCUValidation(prev => !prev)
}, [])
const handleDataConsentValidation = useCallback(() => {
setDataConsentValidation(prev => !prev)
}, [])
const handleTermValidate = useCallback(async () => {
const termsService = new TermsService(client)
const createdTerm = await termsService.createTerm()
if (createdTerm) {
dispatch(
updateTermValidation({
accepted: true,
versionType: await termsService.getTermsVersionType(),
})
)
navigate('/consumption')
}, [dispatch, client, navigate])
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{termsStatus.versionType === 'major' ||
termsStatus.versionType === 'init' ? (
<>
<div className="terms-content">
<DataShareConsentContent />
<label
className={classNames('checkbox', {
['answer-checked']: dataConsentValidation,
})}
>
<input
type={'checkbox'}
name="Data-consent-validation"
onChange={handleDataConsentValidation}
checked={dataConsentValidation}
/>
{t('dataShare.validDataConsent')}
</label>
<label
className={classNames('checkbox', {
['answer-checked']: GCUValidation,
})}
>
<input
type={'checkbox'}
name="GCU-validation"
onChange={handleGCUValidate}
checked={GCUValidation}
/>
<span>
{decoreText(t('dataShare.validCGU'), () => toggleCGUModal())}
{decoreText(t('dataShare.validLegal'), () =>
toggleLegalNoticeModal()
)}
</span>
</label>
</div>
<div className="terms-footer">
<Button
aria-label={t('dataShare.accessibility.button_accept')}
onClick={handleTermValidate}
className={classNames('gcu-modal-button', {
['disabled']: !GCUValidation || !dataConsentValidation,
})}
disabled={!GCUValidation || !dataConsentValidation}
classes={{
root: 'btn-profile-next rounded',
label: 'text-16-bold',
}}
>
{t('dataShare.button_accept')}
</Button>
</div>
</>
) : (
<>
<div className="terms-content">
</div>
<div className="terms-footer">
<Button
aria-label={t('minorUpdate.button')}
onClick={handleTermValidate}
className={'gcu-modal-button'}
classes={{
root: 'btn-profile-next rounded',
label: 'text-16-bold',
}}
>
{t('minorUpdate.button')}
</Button>
</div>
</>
)}
<CGUModal open={openCGUModal} handleCloseClick={toggleCGUModal} />
<LegalNoticeModal
open={openLegalNoticeModal}
handleCloseClick={toggleLegalNoticeModal}
/>