BulkActionCheckbox.tsx
3 years ago
BulkActionSelect.module.scss
3 years ago
BulkActionSelect.tsx
3 years ago
BulkActionSelect.tsx
39 lines
| 1 | import pageStyles from '@givewp/components/ListTable/ListTablePage/ListTablePage.module.scss'; |
| 2 | import styles from './BulkActionSelect.module.scss'; |
| 3 | import {__} from '@wordpress/i18n'; |
| 4 | import Select from '@givewp/components/ListTable/Select'; |
| 5 | import {useState} from 'react'; |
| 6 | |
| 7 | let selected = ''; |
| 8 | |
| 9 | export const BulkActionSelect = ({bulkActions = null, showModal, data, parameters}) => { |
| 10 | const [selectedState, setSelectedState] = useState(selected); |
| 11 | if (!bulkActions) { |
| 12 | return null; |
| 13 | } |
| 14 | |
| 15 | const changeSelected = (event) => { |
| 16 | selected = event.target.value; |
| 17 | setSelectedState(event.target.value); |
| 18 | }; |
| 19 | |
| 20 | return ( |
| 21 | <form id={styles.bulkActionsForm} onSubmit={showModal}> |
| 22 | <Select name="giveListTableBulkActions" value={selectedState} onChange={changeSelected}> |
| 23 | <option value="">{__('Bulk Actions', 'give')}</option> |
| 24 | {bulkActions.map((action) => { |
| 25 | if (typeof action?.isVisible == 'function' && !action.isVisible(data, parameters)) { |
| 26 | return null; |
| 27 | } |
| 28 | return ( |
| 29 | <option key={action.value} value={action.value}> |
| 30 | {action.label} |
| 31 | </option> |
| 32 | ); |
| 33 | })} |
| 34 | </Select> |
| 35 | <button className={pageStyles.addFormButton}>{__('Apply', 'give')}</button> |
| 36 | </form> |
| 37 | ); |
| 38 | }; |
| 39 |