Skip to content

Commit

Permalink
feat(dashboard,app): only healthcare professional
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Mar 28, 2022
1 parent cf816b5 commit 7d220fb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions api/src/controllers/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ router.put(
enabled: z.optional(z.boolean()),
required: z.optional(z.boolean()),
showInStats: z.optional(z.boolean()),
onlyHealthcareProfessional: z.optional(z.boolean()),
options: z.optional(z.array(z.string())),
})
.strict();
Expand Down
4 changes: 3 additions & 1 deletion app/src/scenes/Persons/FileMedical.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import InputLabelled from '../../components/InputLabelled';
import colors from '../../utils/colors';
import CustomFieldInput from '../../components/CustomFieldInput';
import { customFieldsPersonsMedicalSelector } from '../../recoil/persons';
import { userState } from '../../recoil/auth';

const FileMedical = ({ navigation, editable, onChange, onUpdatePerson, onEdit, isUpdateDisabled, updating, backgroundColor, person }) => {
const customFieldsPersonsMedical = useRecoilValue(customFieldsPersonsMedicalSelector);

const user = useRecoilValue(userState);
const scrollViewRef = useRef(null);
const refs = useRef({});
const _scrollToInput = (ref) => {
Expand Down Expand Up @@ -49,6 +50,7 @@ const FileMedical = ({ navigation, editable, onChange, onUpdatePerson, onEdit, i
{(customFieldsPersonsMedical || [])
.filter((f) => f)
.filter((f) => f.enabled)
.filter((f) => !f.onlyHealthcareProfessional || user.healthcareProfessional)
.map((field) => {
const { label, name } = field;
return (
Expand Down
30 changes: 27 additions & 3 deletions dashboard/src/components/TableCustomFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useApi from '../services/api';
import ButtonCustom from './ButtonCustom';
import SelectCustom from './SelectCustom';
import Table from './table';
import QuestionMarkButton from './QuestionMarkButton';

const newField = () => ({
// Todo: I guess could use crypto here.
Expand All @@ -23,7 +24,7 @@ const newField = () => ({

const getValueFromType = (type) => typeOptions.find((opt) => opt.value === type);

const TableCustomFields = ({ data, customFields }) => {
const TableCustomFields = ({ data, customFields, showHealthcareProfessionnalColumn = false }) => {
const [isSubmitting, setIsSubmitting] = useState(false);
const [mutableData, setMutableData] = useState(data);
const [editingField, setEditingField] = useState(null);
Expand All @@ -41,6 +42,11 @@ const TableCustomFields = ({ data, customFields }) => {
setMutableData(mutableData.map((field) => (field.name !== fieldToUpdate.name ? field : { ...fieldToUpdate, showInStats })));
};

const onOnlyHealthcareProfessionalChange = (fieldToUpdate) => (event) => {
const onlyHealthcareProfessional = event.target.checked;
setMutableData(mutableData.map((field) => (field.name !== fieldToUpdate.name ? field : { ...fieldToUpdate, onlyHealthcareProfessional })));
};

const onSaveField = async (editedField) => {
const isUpdate = !!mutableData.find((f) => f.name === editedField.name);
const newData = isUpdate ? mutableData.map((field) => (field.name !== editedField.name ? field : editedField)) : [...mutableData, editedField];
Expand Down Expand Up @@ -137,12 +143,29 @@ const TableCustomFields = ({ data, customFields }) => {
render: (f) => <CellWrapper>{!['enum', 'multi-choice'].includes(f.type) ? null : (f?.options || []).join(', ')}</CellWrapper>,
},
{ title: 'Activé', dataKey: 'enabled', render: (f) => <input type="checkbox" checked={f.enabled} onChange={onEnabledChange(f)} /> },
!showHealthcareProfessionnalColumn
? null
: {
title: (
<div>
Professionnel
<br /> santé
<QuestionMarkButton
onClick={() => {
alert('Le champ ne sera visible que par les comptes de type "professionnel de santé" dans un onglet dédié.');
}}
/>
</div>
),
dataKey: 'onlyHealthcareProfessional',
render: (f) => <input type="checkbox" checked={f.onlyHealthcareProfessional} onChange={onOnlyHealthcareProfessionalChange(f)} />,
},
{
title: (
<>
Voir dans les
<br />
satistiques
statistiques
</>
),
dataKey: 'showInStats',
Expand All @@ -154,7 +177,8 @@ const TableCustomFields = ({ data, customFields }) => {
small: true,
render: (f) => <ButtonCustom title="Supprimer" loading={isSubmitting} onClick={() => onDelete(f)} width={75} color="danger" />,
},
]}
// Remove null fields
].filter((e) => e)}
/>
<ButtonsWrapper>
<ButtonCustom title="Ajouter un champ" loading={isSubmitting} onClick={() => setIsNewField(true)} width={200} />
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/scenes/organisation/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ const View = () => {
<Row>
<TableCustomFields
customFields="customFieldsPersonsMedical"
showHealthcareProfessionnalColumn
key="customFieldsPersonsMedical"
data={(() => {
if (Array.isArray(organisation.customFieldsPersonsMedical)) return organisation.customFieldsPersonsMedical;
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/scenes/person/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ const Summary = ({ person }) => {
</Col>
{customFieldsPersonsMedical
.filter((f) => f.enabled)
.filter((f) => !f.onlyHealthcareProfessional || user.healthcareProfessional)
.map((field) => (
<CustomFieldInput model="person" values={values} handleChange={handleChange} field={field} key={field.name} />
))}
Expand Down

0 comments on commit 7d220fb

Please sign in to comment.