.
This commit is contained in:
parent
a673a3f3d3
commit
9f655d47c0
@ -1,8 +1,13 @@
|
|||||||
import { DataTable, DataTableSkeleton, ErrorOverlay, SimpleEmptyState } from "@/components";
|
import {
|
||||||
|
ColorBadge,
|
||||||
|
DataTable,
|
||||||
|
DataTableSkeleton,
|
||||||
|
ErrorOverlay,
|
||||||
|
SimpleEmptyState,
|
||||||
|
} from "@/components";
|
||||||
import { DataTableToolbar } from "@/components/DataTable/DataTableToolbar";
|
import { DataTableToolbar } from "@/components/DataTable/DataTableToolbar";
|
||||||
import { useDataTable, useDataTableContext } from "@/lib/hooks";
|
import { useDataTable, useDataTableContext } from "@/lib/hooks";
|
||||||
import {
|
import {
|
||||||
Badge,
|
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@ -39,10 +44,6 @@ export const QuotesDataTable = ({
|
|||||||
|
|
||||||
const [activeRow, setActiveRow] = useState<Row<IListQuotes_Response_DTO> | undefined>(undefined);
|
const [activeRow, setActiveRow] = useState<Row<IListQuotes_Response_DTO> | undefined>(undefined);
|
||||||
|
|
||||||
const resetActiveRowIndex = (id?: number) => {
|
|
||||||
setActiveRowIndex(id ? id : 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { useList } = useQuotes();
|
const { useList } = useQuotes();
|
||||||
|
|
||||||
const { data, isPending, isError, error } = useList({
|
const { data, isPending, isError, error } = useList({
|
||||||
@ -98,9 +99,7 @@ export const QuotesDataTable = ({
|
|||||||
id: "reference" as const,
|
id: "reference" as const,
|
||||||
accessorKey: "reference",
|
accessorKey: "reference",
|
||||||
header: () => <>{t("quotes.list.columns.reference")}</>,
|
header: () => <>{t("quotes.list.columns.reference")}</>,
|
||||||
cell: ({ row: { original } }) => (
|
cell: ({ renderValue }) => <div className='text-left text-ellipsis'>{renderValue()}</div>,
|
||||||
<div className='text-left text-ellipsis'>{original.reference}</div>
|
|
||||||
),
|
|
||||||
enableResizing: false,
|
enableResizing: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -108,7 +107,7 @@ export const QuotesDataTable = ({
|
|||||||
accessorKey: "status",
|
accessorKey: "status",
|
||||||
header: () => <>{t("quotes.list.columns.status")}</>,
|
header: () => <>{t("quotes.list.columns.status")}</>,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
cell: ({ renderValue }: { renderValue: () => any }) => <Badge>{renderValue()}</Badge>,
|
cell: ({ row: { original } }) => <ColorBadge label={original.status} />,
|
||||||
enableResizing: false,
|
enableResizing: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
20
client/src/components/ColorBadget/ColorBadget.tsx
Normal file
20
client/src/components/ColorBadget/ColorBadget.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { Badge } from "@/ui";
|
||||||
|
|
||||||
|
function stringToColor(str: string) {
|
||||||
|
let hash = 0;
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
||||||
|
}
|
||||||
|
let color = "#";
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
const value = (hash >> (i * 8)) & 0xff;
|
||||||
|
color += ("00" + value.toString(16)).substr(-2);
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ColorBadge = ({ label }: { label: string }) => {
|
||||||
|
const backgroundColor = stringToColor(label);
|
||||||
|
|
||||||
|
return <Badge style={{ backgroundColor, color: "#fff" }}>{label}</Badge>;
|
||||||
|
};
|
||||||
1
client/src/components/ColorBadget/index.ts
Normal file
1
client/src/components/ColorBadget/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from "./ColorBadget";
|
||||||
@ -1,5 +1,6 @@
|
|||||||
export * from "./ButtonGroup";
|
export * from "./ButtonGroup";
|
||||||
export * from "./Buttons";
|
export * from "./Buttons";
|
||||||
|
export * from "./ColorBadget";
|
||||||
export * from "./Container";
|
export * from "./Container";
|
||||||
export * from "./CustomButtons";
|
export * from "./CustomButtons";
|
||||||
export * from "./CustomDialog";
|
export * from "./CustomDialog";
|
||||||
@ -13,4 +14,5 @@ export * from "./LoadingSpinner";
|
|||||||
export * from "./PDFViewer";
|
export * from "./PDFViewer";
|
||||||
export * from "./ProtectedRoute";
|
export * from "./ProtectedRoute";
|
||||||
//export * from "./SorteableDataTable";
|
//export * from "./SorteableDataTable";
|
||||||
|
|
||||||
export * from "./TailwindIndicator";
|
export * from "./TailwindIndicator";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user