Skip to content

Commit

Permalink
feat: VIN-366 - adicionado funcionalidade de checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderleik committed Mar 19, 2024
1 parent 85063d0 commit a61a1ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ListAddressComponent = () => {
setEditingAddress(selectedAddress[0]);
setVisibleEditDialog(true);
} else {
alert('Selecione um vinho para editar.');
alert('Selecione um endereço para editar.');
}
};

Expand Down
30 changes: 27 additions & 3 deletions frontend/src/components/registration/forms/ListPersonComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { createPerson, updatePerson, deletePerson } from '../../../service/regis
const ListPersonComponent = () => {
const { persons, navigate, fetchPersons } = useListPersonComponentHook();
const [selectedPerson, setSelectedPerson] = useState(null);
const [editingPerson, setEditingPerson] = useState(null);
const [visibleEditDialog, setVisibleEditDialog] = useState(false);
const dt = useRef(null);

const [filters, setFilters] = useState({
Expand Down Expand Up @@ -42,10 +44,32 @@ const ListPersonComponent = () => {
return persons.address ? true : false;
};

const onSelectionChange = (e) => {
setSelectedPerson(e.value);
};

const onSelectAllChange = (e) => {
const _selectedPerson = e.checked ? persons.map(scale => scale) : null;
if (_selectedPerson) {
setSelectedPerson(_selectedPerson);
} else {
setSelectedPerson(null);
}
};

const onNewClick = () => {
navigate('/registration');
};

const onEditClick = () => {
if (selectedPerson && selectedPerson.length === 1) {
setEditingPerson(selectedPerson[0]);
setVisibleEditDialog(true);
} else {
alert('Selecione uma pessoa para editar.');
}
};

const rightToolbarTemplate = () => {
return <Button rounded label="CSV" icon="pi pi-upload" className="p-button-help" onClick={exportCSV} raised />;
}
Expand All @@ -55,7 +79,7 @@ const ListPersonComponent = () => {
<>
<div className="flex flex-wrap gap-2">
<Button rounded label="Novo" icon="pi pi-plus" severity="success" onClick={onNewClick} raised />
<Button rounded label="Editar" icon="pi pi-pencil" severity="secondary" onClick={''} disabled={!selectedPerson || selectedPerson.length !== 1} raised />
<Button rounded label="Editar" icon="pi pi-pencil" severity="secondary" onClick={onEditClick} disabled={!selectedPerson || selectedPerson.length !== 1} raised />
</div>
</>

Expand Down Expand Up @@ -130,8 +154,8 @@ const ListPersonComponent = () => {
selectionMode="multiple"
selection={selectedPerson}

// onSelectionChange={onSelectionChange}
// onSelectAll={onSelectAllChange}
onSelectionChange={onSelectionChange}
onSelectAll={onSelectAllChange}
tableStyle={{ width: '50rem' }}
emptyMessage="Nenhum registro encontrado"
ref={dt}
Expand Down

0 comments on commit a61a1ff

Please sign in to comment.