brilliant-orangeB
Refine2y ago
27 replies
brilliant-orange

How to use props?

PointList receives points as props.
How do I change the points data to be used in useDataGrid, useExport, useForm?
export default function PointList({ points }: any) {
  type PointDetail = IPointDetailItem[] | ''

  console.log(222)
  console.log(points)
  const [pointDetail, setPointDetail] = useState<PointDetail>('')
  const [open, setOpen] = React.useState(false)
  const [startValue, setStartValue] = React.useState<Dayjs | null>(null)
  const [endValue, setEndValue] = React.useState<Dayjs | null>(null)

  const handleClose = () => setOpen(false)

  const handleOpen = (pointDetail: PointDetail) => {
    setPointDetail(pointDetail)
    setOpen(true)
  }

  const { dataGridProps, search, filters } = useDataGrid<BaseRecord, HttpError, IPointsFilterVariables>({
    pagination: {
      mode: 'server', // Client 기준 페이지네이션
    },
    initialPageSize: 10,
    onSearch: (params) => {
      const filters: CrudFilters = []
      const { q, points } = params

      filters.push({
        field: 'q',
        operator: 'eq',
        value: q !== '' ? q : undefined,
      })

      filters.push({
        field: 'points',
        operator: 'eq',
        value: q !== '' ? q : undefined,
      })

      return filters
    },
  })

  const { triggerExport, isLoading: exportLoading } = useExport<IPointValues>({
    filters,
    pageSize: 50,
    maxItemCount: 50,
    mapData: (item) => {
      console.log(1111)
      console.log(item)
      return {
        id: item.id,
        주문번호: item.order_no,
        주문일: item.order_date,
      }
    },
  })

  const { register, handleSubmit, control, reset } = useForm<BaseRecord, HttpError, IPointsFilterVariables>({
    defaultValues: {
      q: getDefaultFilter('q', filters, 'eq'),
      points: getDefaultFilter('points', filters, 'eq'),
    },
  })
...

getServerSideProps to get points
  const points = pointResponse.json()
 return {
    props: {
      points,
      ...translateProps,
    },
  }
Was this page helpful?