feat: add state to every check and effect to check all

This commit is contained in:
RadoslavDimchev 2023-11-21 06:52:01 +02:00
parent d39a1f88a3
commit 751485b700
3 changed files with 27 additions and 4 deletions

View File

@ -5,13 +5,18 @@ import ManagementTableRow from './ManagementTableRow'
type ManagementTableBodyProps = { type ManagementTableBodyProps = {
filteredValidators: Validator[] filteredValidators: Validator[]
isAllSelected: boolean
} }
const ManagementTableBody = ({ filteredValidators }: ManagementTableBodyProps) => { const ManagementTableBody = ({ filteredValidators, isAllSelected }: ManagementTableBodyProps) => {
return ( return (
<tbody> <tbody>
{filteredValidators.map(validator => ( {filteredValidators.map(validator => (
<ManagementTableRow key={validator.address} validator={validator} /> <ManagementTableRow
key={validator.address}
validator={validator}
isAllSelected={isAllSelected}
/>
))} ))}
{filteredValidators.length === 0 && ( {filteredValidators.length === 0 && (
<tr> <tr>

View File

@ -18,5 +18,6 @@ type Story = StoryObj<typeof meta>
export const Default: Story = { export const Default: Story = {
args: { args: {
validator: VALIDATORS_DATA[0], validator: VALIDATORS_DATA[0],
isAllSelected: false,
}, },
} }

View File

@ -1,3 +1,4 @@
import { useEffect, useState } from 'react'
import { Checkbox, Text } from '@status-im/components' import { Checkbox, Text } from '@status-im/components'
import { OptionsIcon } from '@status-im/icons' import { OptionsIcon } from '@status-im/icons'
@ -6,13 +7,29 @@ import { Validator } from './ManagementTable'
type ManagementTableRowProps = { type ManagementTableRowProps = {
validator: Validator validator: Validator
isAllSelected: boolean
} }
const ManagementTableRow = ({ validator }: ManagementTableRowProps) => { const ManagementTableRow = ({ validator, isAllSelected }: ManagementTableRowProps) => {
const [isSelected, setIsSelected] = useState(false)
useEffect(() => {
setIsSelected(isAllSelected)
}, [isAllSelected])
const handleChangeIsSelected = () => {
setIsSelected(state => !state)
}
return ( return (
<tr> <tr>
<td> <td>
<Checkbox id={validator.address} variant="outline" /> <Checkbox
id={validator.address}
variant="outline"
selected={isSelected}
onCheckedChange={handleChangeIsSelected}
/>
</td> </td>
<td> <td>
<ValidatorProfile number={validator.number} address={validator.address} /> <ValidatorProfile number={validator.number} address={validator.address} />