Skip to content
Snippets Groups Projects
Commit c1342f9d authored by Yoan VALLET's avatar Yoan VALLET
Browse files

feat: create report attributes

parent 1ce99796
Branches
Tags
1 merge request!113Features/us221 report view creation
import { DateTime } from 'luxon'
import { UserProfile } from 'models' import { UserProfile } from 'models'
import { atom } from 'recoil' import { atom } from 'recoil'
...@@ -11,6 +12,10 @@ export const userProfileState = atom<UserProfile>({ ...@@ -11,6 +12,10 @@ export const userProfileState = atom<UserProfile>({
haveSeenWelcomeModal: false, haveSeenWelcomeModal: false,
haveSeenOldFluidModal: false, haveSeenOldFluidModal: false,
notificationEcogesture: [], notificationEcogesture: [],
sendReportNotification: false, report: {
sendReportNotification: false,
haveSeenLastReport: true,
monthlyReportDate: DateTime.fromISO('0000-00-00T00:00:00.000Z'),
},
}, },
}) })
...@@ -16,11 +16,20 @@ const ReportOptions: React.FC = () => { ...@@ -16,11 +16,20 @@ const ReportOptions: React.FC = () => {
const updateUserProfileReport = useCallback( const updateUserProfileReport = useCallback(
async (value: boolean) => { async (value: boolean) => {
const userProfileService = new UserProfileService(client) const userProfileService = new UserProfileService(client)
await userProfileService const reportAttributes = {
.updateUserProfile({ sendReportNotification: value }) sendReportNotification: value,
.then(updatedUserProfile => { haveSeenLastReport: userProfile.report.haveSeenLastReport,
updatedUserProfile && setUserProfile(updatedUserProfile) monthlyReportDate: userProfile.report.monthlyReportDate,
}) }
try {
await userProfileService
.updateUserProfile({ report: reportAttributes })
.then(updatedUserProfile => {
updatedUserProfile && setUserProfile(updatedUserProfile)
})
} catch (err) {
console.log(err)
}
}, },
[setUserProfile] [setUserProfile]
) )
...@@ -46,7 +55,8 @@ const ReportOptions: React.FC = () => { ...@@ -46,7 +55,8 @@ const ReportOptions: React.FC = () => {
value="true" value="true"
onChange={handleChange} onChange={handleChange}
checked={ checked={
userProfile && userProfile.sendReportNotification === true userProfile &&
userProfile.report.sendReportNotification === true
? true ? true
: false : false
} }
...@@ -61,7 +71,8 @@ const ReportOptions: React.FC = () => { ...@@ -61,7 +71,8 @@ const ReportOptions: React.FC = () => {
value="false" value="false"
onChange={handleChange} onChange={handleChange}
checked={ checked={
userProfile && userProfile.sendReportNotification === false userProfile &&
userProfile.report.sendReportNotification === false
? true ? true
: false : false
} }
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
"haveSeenWelcomeModal": false, "haveSeenWelcomeModal": false,
"haveSeenOldFluidModal": false, "haveSeenOldFluidModal": false,
"notificationEcogesture": ["0085", "0092"], "notificationEcogesture": ["0085", "0092"],
"sendReportNotification": false "report": {
"sendReportNotification": false,
"haveSeenLastReport": true,
"monthlyReportDate": "0000-00-00T00:00:00.000Z"
}
} }
] ]
...@@ -8,6 +8,7 @@ export * from './fluid.model' ...@@ -8,6 +8,7 @@ export * from './fluid.model'
export * from './indicator.model' export * from './indicator.model'
export * from './konnector.model' export * from './konnector.model'
export * from './modal.model' export * from './modal.model'
export * from './report.model'
export * from './timePeriod.model' export * from './timePeriod.model'
export * from './trigger.model' export * from './trigger.model'
export * from './userProfile.model' export * from './userProfile.model'
import { DateTime } from 'luxon'
export interface ReportAttributes {
sendReportNotification: boolean
haveSeenLastReport: boolean
monthlyReportDate: DateTime
}
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import { ReportAttributes } from './report.model'
export interface UserProfile { export interface UserProfile {
id: string id: string
...@@ -8,5 +9,5 @@ export interface UserProfile { ...@@ -8,5 +9,5 @@ export interface UserProfile {
haveSeenWelcomeModal: boolean haveSeenWelcomeModal: boolean
haveSeenOldFluidModal: DateTime | false haveSeenOldFluidModal: DateTime | false
notificationEcogesture: string[] notificationEcogesture: string[]
sendReportNotification: boolean report: ReportAttributes
} }
...@@ -2,6 +2,7 @@ import { Client } from 'cozy-client' ...@@ -2,6 +2,7 @@ import { Client } from 'cozy-client'
import { UserProfile } from 'models' import { UserProfile } from 'models'
import { USERPROFILE_DOCTYPE } from 'doctypes' import { USERPROFILE_DOCTYPE } from 'doctypes'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import { ReportAttributes } from 'models'
export default class UserProfileService { export default class UserProfileService {
private readonly _client: Client private readonly _client: Client
...@@ -24,7 +25,13 @@ export default class UserProfileService { ...@@ -24,7 +25,13 @@ export default class UserProfileService {
} }
public async updateUserProfile(attributes: { public async updateUserProfile(attributes: {
[key: string]: string | string[] | boolean | number | DateTime [key: string]:
| string
| string[]
| boolean
| number
| DateTime
| ReportAttributes
}): Promise<UserProfile | null> { }): Promise<UserProfile | null> {
const { data: userProfile } = await this._client const { data: userProfile } = await this._client
.query(this._client.find(USERPROFILE_DOCTYPE).limitBy(1)) .query(this._client.find(USERPROFILE_DOCTYPE).limitBy(1))
......
...@@ -21,7 +21,7 @@ const monthlyReportNotification = async ({ ...@@ -21,7 +21,7 @@ const monthlyReportNotification = async ({
log('info', 'Fetching user profile...') log('info', 'Fetching user profile...')
const upm = new UserProfileService(client) const upm = new UserProfileService(client)
const userProfil = await upm.getUserProfile() const userProfil = await upm.getUserProfile()
if (!userProfil || !userProfil.sendReportNotification) { if (!userProfil || !userProfil.report.sendReportNotification) {
log('info', 'End of process - Report Notification disabled in user profile') log('info', 'End of process - Report Notification disabled in user profile')
return return
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment