Skip to content

Commit

Permalink
feat(fe-piattaforma): fe updates 07212022
Browse files Browse the repository at this point in the history
  • Loading branch information
niccolo.valente committed Jul 21, 2022
1 parent c3dad78 commit 545e6c6
Show file tree
Hide file tree
Showing 33 changed files with 874 additions and 599 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@ import { Icon } from 'design-react-kit';
import { useAppSelector } from '../../../../../redux/hooks';
import { selectModalPayload } from '../../../../../redux/features/modal/modalSlice';

const id = 'delete-project';
const id = 'delete-entity';

interface DeleteAuthorityModalI {
onConfirm: (id: string) => void;
interface DeleteEntityModalI {
onConfirm: (payload: any) => void;
onClose: () => void;
text: string;
}

const DeleteProjectModal = ({
text,
onClose,
onConfirm,
}: DeleteAuthorityModalI) => {
const DeleteEntityModal = ({ onClose, onConfirm }: DeleteEntityModalI) => {
const payload = useAppSelector(selectModalPayload);

return (
<GenericModal
id={id}
primaryCTA={{
label: 'Conferma',
onClick: () => onConfirm(payload?.projectId),
onClick: () => onConfirm(payload),
}}
secondaryCTA={{
label: 'Annulla',
Expand All @@ -41,10 +36,10 @@ const DeleteProjectModal = ({
aria-label='Errore'
/>
</div>
<div className='text-center'>{text}</div>
<div className='text-center'>{payload?.text}</div>
</div>
</GenericModal>
);
};

export default DeleteProjectModal;
export default DeleteEntityModal;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AccordionAddress: React.FC<AccordionAddressI> = ({
canBeDeleted = false,
// handleOnToggle,
}) => {
const [addressOpen, setAddressOpen] = useState(false);
const [addressOpen, setAddressOpen] = useState(index === 1);
// const accordionToggleHandler = (isOpen: boolean) => {
// if (handleOnToggle) handleOnToggle(isOpen);
// };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AccordionAddressList: React.FC<AccordionAddressListI> = ({
};

return (
<div className='mx-5'>
<div>
{addressList
.filter((address) => !address.indirizzoSede?.cancellato)
.map((address, index, arr) => (
Expand All @@ -63,30 +63,32 @@ const AccordionAddressList: React.FC<AccordionAddressListI> = ({
}
/>
))}
<div
className={clsx(
'w-100',
'mb-5',
'mt-3',
'd-flex',
'justify-content-end'
)}
>
<Button
onClick={newAddressHandler}
className='d-flex justify-content-between'
type='button'
{!isReadOnly && (
<div
className={clsx(
'w-100',
'mb-5',
'mt-3',
'd-flex',
'justify-content-end'
)}
>
<Icon
color='primary'
icon='it-plus-circle'
size='sm'
className='mr-2'
aria-label='Aggiungi'
/>
Aggiungi Indirizzo
</Button>
</div>
<Button
onClick={newAddressHandler}
className='d-flex justify-content-between'
type='button'
>
<Icon
color='primary'
icon='it-plus-circle'
size='sm'
className='mr-2'
aria-label='Aggiungi'
/>
Aggiungi Indirizzo
</Button>
</div>
)}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';
import withFormHandler, {
withFormHandlerProps,
} from '../../../../../hoc/withFormHandler';
import FormUser from '../../../../../pages/forms/formUser';
import { selectUsers } from '../../../../../redux/features/administrativeArea/administrativeAreaSlice';
import { useAppSelector } from '../../../../../redux/hooks';
import {
formFieldI,
newForm,
newFormField,
} from '../../../../../utils/formHelper';
import Form from '../../../../Form/form';
import Input from '../../../../Form/input';
import Select from '../../../../Form/select';

interface FacilitatorI {
creation?: boolean;
formDisabled?: boolean;
sendNewValues?: (param?: { [key: string]: formFieldI['value'] }) => void;
setIsFormValid?: (param: boolean | undefined) => void;
}

interface FacilitatorFormI extends FacilitatorI, withFormHandlerProps {}

const FormFacilitator: React.FC<FacilitatorFormI> = (props) => {
const {
setFormValues = () => ({}),
form,
onInputChange = () => ({}),
sendNewValues = () => ({}),
isValidForm,
setIsFormValid = () => ({}),
getFormValues = () => ({}),
creation = false,
formDisabled = false,
} = props;

const [newFormValues, setNewFormValues] = useState<{
[key: string]: formFieldI['value'];
}>({});
const userDetails = useAppSelector(selectUsers).detail?.dettaglioUtente;

useEffect(() => {
if (form && newFormValues)
sendNewValues({ ...newFormValues, ...getFormValues() });
}, [form, newFormValues]);

useEffect(() => {
if (userDetails) {
setFormValues(userDetails);
}
}, [userDetails]);

const onInputDataChange = (
value: formFieldI['value'],
field?: formFieldI['field']
) => {
onInputChange(value, field);
setIsFormValid(isValidForm);
};

const bootClass = 'justify-content-between px-0 px-lg-5 mx-2';

return (
<>
<FormUser
creation={creation}
formDisabled={!!formDisabled}
sendNewValues={(newData?: { [key: string]: formFieldI['value'] }) =>
setNewFormValues({ ...newData })
}
setIsFormValid={(value: boolean | undefined) => setIsFormValid(!!value)}
/>
<Form>
<Form.Row className={clsx(bootClass, 'mt-0')}>
{formDisabled ? (
<Input
{...form?.tipoContratto}
required
label='Tipo di Contratto'
col='col-12 col-lg-6'
// placeholder='Tipologia di contratto'
onInputChange={(value, field) => {
onInputDataChange(value, field);
}}
/>
) : (
<Select
{...form?.tipoContratto}
required
value={form?.tipoContratto.value as string}
col='col-12 col-lg-6'
label='Tipo di Contratto'
options={[
{ label: 'Volontario', value: 'Volontario' },
{ label: 'Dipendente', value: 'Dipendente' },
{
label: 'Collaboratore',
value: 'Collaboratore',
},
]}
onInputChange={onInputDataChange}
wrapperClassName='mb-5'
aria-label='contratto'
/>
)}
</Form.Row>
</Form>
</>
);
};

const form = newForm([
newFormField({
field: 'tipoContratto',
id: 'tipoContratto',
}),
]);

export default withFormHandler({ form }, FormFacilitator);
Loading

0 comments on commit 545e6c6

Please sign in to comment.