feat: deals filters
This commit is contained in:
33
src/components/selects/BoardSelect/BoardSelect.tsx
Normal file
33
src/components/selects/BoardSelect/BoardSelect.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import ObjectSelect, {
|
||||
ObjectSelectProps,
|
||||
} from "@/components/selects/ObjectSelect/ObjectSelect";
|
||||
import useBoardsList from "@/hooks/lists/useBoardsList";
|
||||
import { BoardSchema } from "@/lib/client";
|
||||
|
||||
type Props = Omit<
|
||||
ObjectSelectProps<BoardSchema | null>,
|
||||
"data" | "getLabelFn" | "getValueFn"
|
||||
> & {
|
||||
projectId?: number;
|
||||
};
|
||||
|
||||
const BoardSelect: FC<Props> = ({ projectId, ...props }) => {
|
||||
const onClear = () => props.onChange(null);
|
||||
|
||||
const { boards } = useBoardsList({ projectId });
|
||||
|
||||
return (
|
||||
<ObjectSelect
|
||||
data={boards}
|
||||
searchable
|
||||
placeholder={"Выберите доску"}
|
||||
onClear={onClear}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default BoardSelect;
|
||||
38
src/components/selects/StatusSelect/StatusSelect.tsx
Normal file
38
src/components/selects/StatusSelect/StatusSelect.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
"use client";
|
||||
|
||||
import { FC, useEffect } from "react";
|
||||
import ObjectSelect, {
|
||||
ObjectSelectProps,
|
||||
} from "@/components/selects/ObjectSelect/ObjectSelect";
|
||||
import useStatusesList from "@/hooks/lists/useStatusesList";
|
||||
import { BoardSchema } from "@/lib/client";
|
||||
|
||||
type Props = Omit<
|
||||
ObjectSelectProps<BoardSchema | null>,
|
||||
"data" | "getLabelFn" | "getValueFn"
|
||||
> & {
|
||||
boardId?: number;
|
||||
};
|
||||
|
||||
const StatusSelect: FC<Props> = ({ boardId, ...props }) => {
|
||||
const onClear = () => props.onChange(null);
|
||||
|
||||
const { statuses } = useStatusesList({ boardId });
|
||||
|
||||
useEffect(() => {
|
||||
if (!boardId) props.onChange(null);
|
||||
}, [boardId]);
|
||||
|
||||
return (
|
||||
<ObjectSelect
|
||||
data={statuses}
|
||||
disabled={!boardId}
|
||||
searchable
|
||||
placeholder={"Выберите статус"}
|
||||
onClear={onClear}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatusSelect;
|
||||
@ -1,59 +1,18 @@
|
||||
import React, { useEffect, useImperativeHandle } from "react";
|
||||
import {
|
||||
MantineReactTable,
|
||||
MRT_ColumnDef,
|
||||
MRT_RowData,
|
||||
MRT_TableInstance,
|
||||
MRT_TableOptions,
|
||||
useMantineReactTable,
|
||||
} from "mantine-react-table";
|
||||
import { MRT_Localization_RU } from "mantine-react-table/locales/ru";
|
||||
import React from "react";
|
||||
import { DataTable, DataTableProps } from "mantine-datatable";
|
||||
|
||||
type Props<T extends MRT_RowData> = {
|
||||
data: T[];
|
||||
onSelectionChange?: (selectedRows: T[]) => void;
|
||||
columns: MRT_ColumnDef<T>[];
|
||||
restProps?: MRT_TableOptions<T>;
|
||||
striped?: boolean | "odd" | "even";
|
||||
};
|
||||
|
||||
export type BaseTableRef<T extends MRT_RowData> = {
|
||||
getTable: () => MRT_TableInstance<T>;
|
||||
};
|
||||
|
||||
function BaseTableInner<T extends MRT_RowData>(
|
||||
{ data, columns, restProps, onSelectionChange, striped = false }: Props<T>,
|
||||
ref: React.Ref<BaseTableRef<T>>
|
||||
) {
|
||||
const table = useMantineReactTable<T>({
|
||||
localization: MRT_Localization_RU,
|
||||
enablePagination: false,
|
||||
data,
|
||||
columns,
|
||||
mantineTableProps: {
|
||||
striped,
|
||||
highlightOnHover: false,
|
||||
},
|
||||
enableTopToolbar: false,
|
||||
enableBottomToolbar: false,
|
||||
enableRowSelection: onSelectionChange !== undefined,
|
||||
...restProps,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!onSelectionChange) return;
|
||||
onSelectionChange(
|
||||
table.getSelectedRowModel().rows.map(r => r.original)
|
||||
);
|
||||
}, [onSelectionChange, table.getState().rowSelection]);
|
||||
|
||||
useImperativeHandle(ref, () => ({ getTable: () => table }));
|
||||
|
||||
return <MantineReactTable table={table} />;
|
||||
function BaseTable<T>(props: DataTableProps<T>) {
|
||||
return (
|
||||
<DataTable
|
||||
withTableBorder={false}
|
||||
withRowBorders
|
||||
striped={false}
|
||||
verticalAlign={"center"}
|
||||
borderRadius={"lg"}
|
||||
backgroundColor={"transparent"}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const BaseTable = React.forwardRef(BaseTableInner) as <T extends MRT_RowData>(
|
||||
props: Props<T> & { ref?: React.Ref<BaseTableRef<T>> }
|
||||
) => React.ReactElement | null;
|
||||
|
||||
export default BaseTable;
|
||||
|
||||
Reference in New Issue
Block a user