Skip to content

Commit

Permalink
feat(fe-piattaforma): fe updates 08042022
Browse files Browse the repository at this point in the history
  • Loading branch information
nicogheart1 committed Aug 4, 2022
2 parents fa77f33 + c11db8f commit d587c92
Show file tree
Hide file tree
Showing 14 changed files with 552 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import Form from '../../../../Form/form';
import Input from '../../../../Form/input';
import GenericModal from '../../../../Modals/GenericModal/genericModal';
import { RegexpType } from '../../../../../utils/validator';
import { useAppSelector } from '../../../../../redux/hooks';
import { selectModalPayload } from '../../../../../redux/features/modal/modalSlice';

const id = 'terminate-entity';

interface TerminateEntityModalI {
onConfirm: (date: string) => void;
onConfirm: (entity: 'program' | 'project', date: string, id?: string) => void;
onClose: () => void;
text: string;
}

interface TerminateEntityModalFullI
Expand All @@ -33,12 +34,12 @@ const form = newForm([
const TerminateEntityModal = ({
onConfirm,
onClose,
text,
form,
onInputChange = () => ({}),
getFormValues = () => ({}),
}: TerminateEntityModalFullI) => {
const [terminationDate, setTerminationDate] = useState('');
const payload = useAppSelector(selectModalPayload);

useEffect(() => {
const newDate = getFormValues()['date'] as string;
Expand Down Expand Up @@ -75,7 +76,13 @@ const TerminateEntityModal = ({
primaryCTA={{
label: 'Conferma',
disabled: !terminationDate,
onClick: () => terminationDate && onConfirm(terminationDate),
onClick: () =>
terminationDate &&
onConfirm(
payload?.entity,
terminationDate,
payload?.entity === 'project' ? payload?.projectId : undefined
),
}}
secondaryCTA={{
label: 'Annulla',
Expand All @@ -92,14 +99,14 @@ const TerminateEntityModal = ({
aria-label='Errore'
/>
</div>
<div className='text-center pb-3'>{text}</div>
<div className='text-center pb-3'>{payload?.text}</div>
<Form>
<Form.Row>
<div className='col'></div>
<Input
{...form?.date}
col='col-6'
max={new Date().toISOString().split('T')[0]}
maximum={new Date().toISOString().split('T')[0]}
placeholder='Seleziona Data'
onInputChange={(value, field) => {
onInputChange(value, field);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Button } from 'design-react-kit';
import React, { useState } from 'react';
import { selectModalPayload } from '../../../../../redux/features/modal/modalSlice';
import { useAppSelector } from '../../../../../redux/hooks';
import { downloadCSV } from '../../../../../utils/common';
import FileInput from '../../../../General/FileInput/FileInput';
import GenericModal from '../../../../Modals/GenericModal/genericModal';

const id = 'upload-csv';

interface UploadCSVModalI {
onConfirm: () => void;
onClose: () => void;
}

const UploadCSVModal = ({ onConfirm, onClose }: UploadCSVModalI) => {
const [step, setStep] = useState(0);
const payload = useAppSelector(selectModalPayload);

const downloadTemplateHandler = () => {
downloadCSV(payload?.data, `${payload?.entity}.csv`);
};

let content = <span></span>;

switch (step) {
case 0:
content = (
<div className='d-flex flex-column align-items-center justify-content-center p-5'>
<p className='py-3'>
Scarica il template relativo alle entità da caricare.
</p>
<Button
color='primary'
outline
onClick={() => downloadTemplateHandler()}
>
Scarica template
</Button>
<div className='w-100 pt-5'>
<FileInput />
</div>
</div>
);
break;
case 1:
content = (
<div className='d-flex justify-content-around align-items-center p-5 text-center'>
<div>
<h4>Riusciti</h4>
<p>12</p>
</div>
<div>
<h4>Falliti</h4>
<p>2</p>
</div>
</div>
);
break;
default:
break;
}

const nextStep = () => {
switch (step) {
case 0:
setStep(1);
break;
case 1:
onConfirm();
break;
default:
break;
}
};

return (
<GenericModal
id={id}
primaryCTA={{
label: 'Conferma',
onClick: nextStep,
}}
secondaryCTA={{
label: 'Annulla',
onClick: onClose,
}}
centerButtons
onClose={onClose}
>
{content}
</GenericModal>
);
};

export default UploadCSVModal;
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { withFormHandlerProps } from '../../../../../hoc/withFormHandler';
import { headings } from '../../../../../pages/administrator/AdministrativeArea/Entities/modals/manageReferal';
import { formTypes } from '../../../../../pages/administrator/AdministrativeArea/Entities/utils';
import {
resetUserDetails,
selectHeadquarters,
selectUsers,
setUserDetails,
setUsersList,
} from '../../../../../redux/features/administrativeArea/administrativeAreaSlice';
import {
Expand Down Expand Up @@ -62,6 +62,11 @@ const ManageFacilitator: React.FC<ManageFacilitatorI> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
dispatch(resetUserDetails());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [creation]);

useEffect(() => {
if (usersList && usersList.length === 0) {
setNoResult(true);
Expand Down Expand Up @@ -89,7 +94,6 @@ const ManageFacilitator: React.FC<ManageFacilitatorI> = ({
)
);
dispatch(GetHeadquarterDetails(headquarterId, authorityId, projectId));
dispatch(setUserDetails(null));
} else if (userId) {
userId &&
(await dispatch(
Expand Down Expand Up @@ -134,6 +138,7 @@ const ManageFacilitator: React.FC<ManageFacilitatorI> = ({
heading={headings}
values={usersList.map((item) => ({
id: item.id || item.codiceFiscale,
codiceFiscale: item.codiceFiscale,
cognome: item.cognome,
nome: item.nome,
}))}
Expand Down Expand Up @@ -168,7 +173,7 @@ const ManageFacilitator: React.FC<ManageFacilitatorI> = ({
centerButtons
>
<div>
{creation && (
{creation ? (
<SearchBar
className={clsx(
'w-100',
Expand All @@ -183,7 +188,7 @@ const ManageFacilitator: React.FC<ManageFacilitatorI> = ({
title='Cerca'
search
/>
)}
) : null}
<div className='mx-5'>{content}</div>
</div>
</GenericModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const ManageHeadquarter: React.FC<ManageHeadquarterI> = ({

setAddressList([...newAddressList]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [movingHeadquarter]);

const handleSelectHeadquarter: CRUDActionsI = {
Expand Down Expand Up @@ -292,7 +293,7 @@ const ManageHeadquarter: React.FC<ManageHeadquarterI> = ({
centerButtons
>
<div>
{creation && (
{creation ? (
<SearchBar
className={clsx(
'w-100',
Expand All @@ -307,7 +308,7 @@ const ManageHeadquarter: React.FC<ManageHeadquarterI> = ({
title='Cerca'
search
/>
)}
) : null}
<div className='mx-5'>{content}</div>
</div>
</GenericModal>
Expand Down
72 changes: 72 additions & 0 deletions fe-piattaforma/src/components/General/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Button, Icon } from 'design-react-kit';
import React, { useRef, useState } from 'react';

const FileInput = () => {
const inputRef = useRef<HTMLInputElement>(null);
const [file, setFile] = useState<string | null>(null);

const addDocument = () => {
if (inputRef.current !== null) {
inputRef.current.click();
}
};
const updateFile = () => {
const input: HTMLInputElement = document.getElementById(
'file'
) as HTMLInputElement;

if (input.files?.length) {
const selectedFile = input.files[0];
const reader = new FileReader();
reader.readAsDataURL(selectedFile);
reader.onloadend = () => {
setFile(selectedFile.name as string);
};
}
};

const removeFile = () => {
const input: HTMLInputElement = document.getElementById(
'file'
) as HTMLInputElement;

if (input.files?.length) {
input.value = '';
setFile(null);
}
};

return (
<div className='w-100 border-bottom'>
<input
type='file'
id='file'
accept='image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv'
ref={inputRef}
className='sr-only'
capture
onChange={updateFile}
/>
<label
htmlFor='file'
className='d-flex align-items-center justify-content-between'
>
<p className='mt-2' style={{ color: '#4c4c4d' }}>
{file ? <strong>{file}</strong> : 'Carica file dal tuo dispositivo'}
</p>
{file && (
<Button icon className='p-2' onClick={removeFile}>
<Icon icon='it-delete' size='sm' color='primary' />
</Button>
)}
{file === null && (
<Button outline color='primary' className='p-2' onClick={addDocument}>
<Icon icon='it-plus' size='sm' color='primary' /> Seleziona file
</Button>
)}
</label>
</div>
);
};

export default FileInput;
Loading

0 comments on commit d587c92

Please sign in to comment.