From e854d39de5ffc731fa4b80ce1980724dbe1deb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Demazi=C3=A8re?= Date: Mon, 4 Apr 2022 11:58:04 +0200 Subject: [PATCH] comment limited to 240 characters create state_id from PUT response --- package.json | 2 +- public/configuration.json | 2 +- .../UEpage/comments/comment/component.js | 37 ++++++++++++------- src/utils/functions/surveyUnitFunctions.js | 12 ++++-- src/utils/synchronize/index.js | 13 ++++--- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index f82a0c370..bc3975d71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pearl", - "version": "0.5.5", + "version": "0.5.6", "private": true, "dependencies": { "@date-io/date-fns": "1.x", diff --git a/public/configuration.json b/public/configuration.json index 4bb60b596..9b16ca41d 100644 --- a/public/configuration.json +++ b/public/configuration.json @@ -5,7 +5,7 @@ "PEARL_API_URL": "https://api.organisation-collecte-enqueteurs.enquetes.developpement.insee.fr", "_PEARL_API_URL_COMMENT_": "url of Pearl API", - "PEARL_AUTHENTICATION_MODE": "keycloak", + "PEARL_AUTHENTICATION_MODE": "anonymous", "_PEARL_AUTHENTICATION_MODE_COMMENT": "The mode of authentication. Currently, App is supporting 'anonymous'", "CHAT_URL": "", "_CHAT_URL_COMMENT_": "url of Pearl Chat" diff --git a/src/components/panel-body/UEpage/comments/comment/component.js b/src/components/panel-body/UEpage/comments/comment/component.js index 50034ddf4..ada422a65 100644 --- a/src/components/panel-body/UEpage/comments/comment/component.js +++ b/src/components/panel-body/UEpage/comments/comment/component.js @@ -1,12 +1,13 @@ import React, { useContext, useState } from 'react'; -import { makeStyles } from '@material-ui/core/styles'; -import TextareaAutosize from '@material-ui/core/TextareaAutosize'; -import Paper from '@material-ui/core/Paper'; import D from 'i18n'; +import Paper from '@material-ui/core/Paper'; import PropTypes from 'prop-types'; import SurveyUnitContext from '../../UEContext'; +import TextareaAutosize from '@material-ui/core/TextareaAutosize'; +import Typography from '@material-ui/core/Typography'; import { getCommentByType } from 'utils/functions/surveyUnitFunctions'; +import { makeStyles } from '@material-ui/core/styles'; import surveyUnitIdbService from 'utils/indexeddb/services/surveyUnit-idb-service'; const useStyles = makeStyles(() => ({ @@ -43,23 +44,31 @@ const Comment = ({ editable }) => { surveyUnitIdbService.addOrUpdate(surveyUnit); }; + const onBlur = event => { + saveUE(event.target.value); + }; + const onChange = event => { setInterviewerComment(event.target.value); - saveUE(event.target.value); }; const classes = useStyles(); return ( - - - + <> + + + + {`${interviewerComment.length}/240`} + ); }; diff --git a/src/utils/functions/surveyUnitFunctions.js b/src/utils/functions/surveyUnitFunctions.js index fffd17d5f..0a1ccea32 100644 --- a/src/utils/functions/surveyUnitFunctions.js +++ b/src/utils/functions/surveyUnitFunctions.js @@ -4,7 +4,7 @@ import { differenceInYears, formatDistanceStrict } from 'date-fns'; import D from 'i18n'; import { contactOutcomeEnum } from 'utils/enum/ContactOutcomeEnum'; import { convertSUStateInToDo } from 'utils/functions/convertSUStateInToDo'; -import surveyUnitDBService from 'utils/indexeddb/services/surveyUnit-idb-service'; +import surveyUnitIdbService from 'utils/indexeddb/services/surveyUnit-idb-service'; import { surveyUnitStateEnum } from 'utils/enum/SUStateEnum'; export const getCommentByType = (type, su) => { @@ -64,7 +64,7 @@ export const areCaEqual = (ca, anotherCa) => { export const deleteContactAttempt = (surveyUnit, contactAttempt) => { const { contactAttempts } = surveyUnit; const newCA = contactAttempts.filter(ca => !areCaEqual(ca, contactAttempt)); - surveyUnitDBService.update({ ...surveyUnit, contactAttempts: newCA }); + surveyUnitIdbService.update({ ...surveyUnit, contactAttempts: newCA }); }; export const getContactAttemptNumber = surveyUnit => @@ -192,7 +192,7 @@ export const addNewState = async (surveyUnit, stateType) => { break; } newSu.selected = false; - await surveyUnitDBService.addOrUpdate(newSu); + await surveyUnitIdbService.addOrUpdate(newSu); }; export const updateStateWithDates = surveyUnit => { @@ -409,3 +409,9 @@ export const getprivilegedPerson = surveyUnit => { const privilegedPerson = persons.find(p => p.privileged); return privilegedPerson ? privilegedPerson : persons[0]; }; + +export const createStateIds = async latestSurveyUnit => { + const { id, states } = latestSurveyUnit; + const previousSurveyUnit = await surveyUnitIdbService.getById(id); + surveyUnitIdbService.addOrUpdateSU({ ...previousSurveyUnit, states }); +}; diff --git a/src/utils/synchronize/index.js b/src/utils/synchronize/index.js index ac63aab8e..dc10a6903 100644 --- a/src/utils/synchronize/index.js +++ b/src/utils/synchronize/index.js @@ -1,8 +1,8 @@ import * as api from 'utils/api'; +import { createStateIds, getLastState } from 'utils/functions'; import { useCallback, useState } from 'react'; -import { getLastState } from 'utils/functions'; import surveyUnitDBService from 'utils/indexeddb/services/surveyUnit-idb-service'; import surveyUnitMissingIdbService from 'utils/indexeddb/services/surveyUnitMissing-idb-service'; import { surveyUnitStateEnum } from 'utils/enum/SUStateEnum'; @@ -67,10 +67,13 @@ const sendData = async (urlPearlApi, authenticationMode) => { ...surveyUnit, lastState, }; - const { error, status } = await api.putDataSurveyUnitById(urlPearlApi, authenticationMode)( - id, - body - ); + const { data: latestSurveyUnit, error, status } = await api.putDataSurveyUnitById( + urlPearlApi, + authenticationMode + )(id, body); + if (!error) { + await createStateIds(latestSurveyUnit); + } if (error && [400, 403, 404, 500].includes(status)) { const { error: tempZoneError } = await api.putSurveyUnitToTempZone( urlPearlApi,