Advertisement
PastebinhoLuisinho

Untitled

Aug 12th, 2024
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use client';
  2.  
  3. import { Stack } from '@mui/material';
  4. import { Button, SelectField, TextField } from '@penzack/ui-components';
  5. import { Controller } from 'react-hook-form';
  6. import InputMask from 'react-input-mask';
  7.  
  8. import {
  9.   optionsLabelBlock,
  10.   optionsLabelStatus,
  11.   optionsLabelWithdrawStatus,
  12.   optionsTypeUser,
  13. } from '@/consts/tableFilter';
  14.  
  15. import { theme } from '@/theme';
  16.  
  17. import { DateRangePicker } from '../DateRangePicker';
  18.  
  19. import { actions } from './TableFilter.controller'
  20.  
  21. import { TableFilterProps } from './TableFilter.types'
  22.  
  23. export const TableFilter = ({
  24.   showStatusField,
  25.   showUserType = true,
  26.   showWithdrawalOptions = false,
  27.   showBlockOptions = false,
  28.   tableId,
  29. }: TableFilterProps) => {
  30.   const controller = actions(tableId)
  31.  
  32.   return (
  33.     <form
  34.       onSubmit={controller.handleSubmit(controller.handleFilterSubmit)}
  35.       style={{
  36.         display: 'flex',
  37.         flexDirection: 'row',
  38.         gap: theme.spacing(4),
  39.         padding: `${theme.spacing(3)}px ${theme.spacing(4)}px`,
  40.       }}
  41.     >
  42.       <Stack direction="row" alignItems="center" gap={2} flex={1} flexWrap="wrap">
  43.         <Controller
  44.           control={controller.control}
  45.           name="date"
  46.           render={({ field }) => <DateRangePicker value={field.value} setValue={field.onChange} />}
  47.         />
  48.         <TextField
  49.           {...controller.register('cognitoId')}
  50.           label=""
  51.           placeholder="Cognito ID"
  52.           name="cognitoId"
  53.           sx={{ width: '100px' }}
  54.         />
  55.         {showUserType && (
  56.           <SelectField
  57.             {...controller.register('type')}
  58.             onChange={(value) => controller.handleSelectType(value)}
  59.             placeholder="Type of user"
  60.             label="Type of user"
  61.             value={controller.selectedType}
  62.             options={optionsTypeUser}
  63.             sx={{ width: '130px' }}
  64.           />
  65.         )}
  66.         <InputMask
  67.           mask={'999.999.999-99'}
  68.           alwaysShowMask={false}
  69.           maskPlaceholder=""
  70.           type={'text'}
  71.           placeholder="000.000.000-00"
  72.           sx={{ width: '160px' }}
  73.           {...controller.register('cpf')}
  74.         >
  75.           {(inputProps) => <TextField {...inputProps} />}
  76.         </InputMask>
  77.         <TextField
  78.           {...controller.register('email')}
  79.           label=""
  80.           placeholder="Email"
  81.           name="email"
  82.           sx={{ width: '200px' }}
  83.         />
  84.         {showStatusField && (
  85.           <SelectField
  86.             {...controller.register('status')}
  87.             onChange={(value) => controller.handleSelectStatus(value)}
  88.             placeholder="Status"
  89.             label="Status"
  90.             value={controller.selectedStatus}
  91.             options={showWithdrawalOptions ? optionsLabelWithdrawStatus : optionsLabelStatus}
  92.             sx={{ width: '140px' }}
  93.           />
  94.         )}
  95.         {showBlockOptions && (
  96.           <SelectField
  97.             {...controller.register('block')}
  98.             onChange={(value) => controller.handleSelectBlock(value)}
  99.             placeholder="Type of block"
  100.             label="Type of block"
  101.             value={controller.selectedBlock}
  102.             options={optionsLabelBlock}
  103.             sx={{ width: '170px' }}
  104.           />
  105.         )}
  106.       </Stack>
  107.       <Button type="submit" variant="outlined" sx={{ minWidth: 105 }}>
  108.         Search
  109.       </Button>
  110.     </form>
  111.   );
  112. };
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement