Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

Editable table (#6)

Brad Barbin7269cba112cd
diff --git a/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx b/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx
index 57c3911659..233f7bb42d 100644
--- a/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx
+++ b/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx
@@ -1,7 +1,7 @@
import { useDebounce } from "@carbon/react";
import type { InputProps } from "@chakra-ui/react";
import { Input } from "@chakra-ui/react";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { useUrlParams } from "~/hooks";
type DebounceInputProps = InputProps & {
@@ -9,12 +9,17 @@ type DebounceInputProps = InputProps & {
};
const DebouncedInput = ({ param, ...props }: DebounceInputProps) => {
+ const initialLoad = useRef(true);
const [params, setParams] = useUrlParams();
const [query, setQuery] = useState(params.get(param) || "");
const [debouncedQuery] = useDebounce(query, 500);
useEffect(() => {
- setParams({ [param]: debouncedQuery, limit: undefined, offset: undefined });
+ if (initialLoad.current) {
+ initialLoad.current = false;
+ } else {
+ setParams({ [param]: debouncedQuery });
+ }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedQuery]);
diff --git a/apps/carbon/app/components/Table/Table.tsx b/apps/carbon/app/components/Table/Table.tsx
index a078f310f0..8cb148f028 100644
--- a/apps/carbon/app/components/Table/Table.tsx
+++ b/apps/carbon/app/components/Table/Table.tsx
@@ -1,21 +1,24 @@
-import { useColor } from "@carbon/react";
+import { useColor, useEscape } from "@carbon/react";
+import { clip } from "@carbon/utils";
import type { ThemeTypings } from "@chakra-ui/react";
+import { VStack } from "@chakra-ui/react";
import {
Box,
Flex,
Grid,
Table as ChakraTable,
- Thead,
Tbody,
- Tr as ChakraTr,
- Th as ChakraTh,
- Td as ChakraTd,
+ Td,
+ Th,
+ Tr,
+ Thead,
chakra,
} from "@chakra-ui/react";
import type {
ColumnDef,
ColumnOrderState,
ColumnPinningState,
+ Row as RowType,
RowSelectionState,
} from "@tanstack/react-table";
import {
@@ -23,18 +26,28 @@ import {
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
-import { AnimatePresence, motion } from "framer-motion";
-import { useEffect, useMemo, useState } from "react";
-
+// import { AnimatePresence } from "framer-motion";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { useVirtual } from "react-virtual";
import { AiFillCaretUp, AiFillCaretDown } from "react-icons/ai";
import {
Header,
IndeterminateCheckbox,
Pagination,
+ // Td,
+ // Th,
+ // Tr,
+ // spring,
usePagination,
useSort,
+ Row,
} from "./components";
-import type { TableAction } from "./types";
+import type {
+ EditableTableCellComponent,
+ Position,
+ TableAction,
+} from "./types";
+import { getAccessorKey, updateNestedProperty } from "./utils";
interface TableProps<T extends object> {
columns: ColumnDef<T>[];
@@ -43,7 +56,9 @@ interface TableProps<T extends object> {
count?: number;
colorScheme?: ThemeTypings["colorSchemes"];
defaultColumnVisibility?: Record<string, boolean>;
+ editableComponents?: Record<string, EditableTableCellComponent<T>>;
withColumnOrdering?: boolean;
+ withInlineEditing?: boolean;
withFilters?: boolean;
withPagination?: boolean;
withSelectableRows?: boolean;
@@ -58,8 +73,10 @@ const Table = <T extends object>({
actions = [],
count = 0,
colorScheme = "blackAlpha",
+ editableComponents = {},
defaultColumnVisibility = {},
withFilters = false,
+ withInlineEditing = false,
withColumnOrdering = false,
withPagination = true,
withSelectableRows = false,
@@ -67,6 +84,13 @@ const Table = <T extends object>({
onRowClick,
onSelectedRowsChange,
}: TableProps<T>) => {
+ const tableContainerRef = useRef<HTMLDivElement>(null);
+
+ const [internalData, setInternalData] = useState<T[]>(data);
+ useEffect(() => {
+ setInternalData(data);
+ }, [data]);
+
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
if (withSelectableRows) columns.unshift(getRowSelectionColumn<T>());
@@ -89,14 +113,15 @@ const Table = <T extends object>({
const columnAccessors = useMemo(
() =>
columns.reduce<Record<string, string>>((acc, column) => {
- if (
- column.header &&
- typeof column.header === "string" &&
- "accessorKey" in column
- ) {
+ const accessorKey: string | undefined = getAccessorKey(column);
+ if (accessorKey?.includes("_"))
+ throw new Error(
+ `Invalid accessorKey ${accessorKey}. Cannot contain '_'`
+ );
+ if (accessorKey && column.header && typeof column.header === "string") {
return {
...acc,
- [column.accessorKey.toString()]: column.header,
+ [accessorKey]: column.header,
};
}
return acc;
@@ -105,7 +130,7 @@ const Table = <T extends object>({
);
const table = useReactTable({
- data,
+ data: internalData,
columns,
state: {
rowSelection,
@@ -118,12 +143,215 @@ const Table = <T extends object>({
onColumnPinningChange: setColumnPinning,
onRowSelectionChange: setRowSelection,
getCoreRowModel: getCoreRowModel(),
+ meta: {
+ // These are not part of the standard API, but are accessible via table.options.meta
+ editableComponents,
+ updateData: (rowIndex, columnId, value) => {
+ setInternalData((previousData) =>
+ previousData.map((row, index) => {
+ if (index === rowIndex) {
+ if (columnId.includes("_") && !(columnId in row)) {
+ updateNestedProperty(row, columnId, value);
+ return row;
+ } else {
+ return {
+ ...row,
+ [columnId]: value,
+ };
+ }
+ }
+ return row;
+ })
+ );
+ },
+ },
});
const selectedRows = withSelectableRows
? table.getSelectedRowModel().flatRows.map((row) => row.original)
: [];
+ const [editMode, setEditMode] = useState(false);
+ const [isEditing, setIsEditing] = useState(false);
+ const [selectedCell, setSelectedCell] = useState<Position>(null);
+
+ const focusOnSelectedCell = useCallback(() => {
+ if (selectedCell == null) return;
+ const cell = tableContainerRef.current?.querySelector(
+ `[data-row="${selectedCell.row}"][data-column="${selectedCell.column}"]`
+ ) as HTMLDivElement;
+ if (cell) cell.focus();
+ }, [selectedCell, tableContainerRef]);
+
+ useEscape(() => {
+ setIsEditing(false);
+ focusOnSelectedCell();
+ });
+
+ const onSelectedCellChange = useCallback(
+ (position: Position) => {
+ if (
+ selectedCell == null ||
+ position == null ||
+ selectedCell.row !== position?.row ||
+ selectedCell.column !== position.column
+ )
+ setSelectedCell(position);
+ },
+ [selectedCell]
+ );
+
+ const isColumnEditable = useCallback(
+ (selectedColumn: number) => {
+ if (!withInlineEditing) return false;
+
+ const columns = table.getVisibleLeafColumns();
+ const column =
+ columns[withSelectableRows ? selectedColumn + 1 : selectedColumn];
+ if (!column) return false;
+
+ const accessorKey = getAccessorKey(column.columnDef);
+ return accessorKey && accessorKey in editableComponents;
+ },
+ [table, editableComponents, withInlineEditing, withSelectableRows]
+ );
+
+ const onCellClick = useCallback(
+ (row: number, column: number) => {
+ // ignore row select checkbox column
+ if (
+ selectedCell?.row === row &&
+ selectedCell?.column === column &&
+ isColumnEditable(column)
+ ) {
+ setIsEditing(true);
+ return;
+ }
+ // ignore row select checkbox column
+ if (column === -1) return;
+ setIsEditing(false);
+ onSelectedCellChange({ row, column });
+ },
+ [selectedCell, isColumnEditable, onSelectedCellChange]
+ );
+
+ const onCellEditUpdate = useCallback(
+ (rowIndex: number, columnId: string) => (value: unknown) => {
+ return table.options.meta?.updateData
+ ? table.options.meta?.updateData(rowIndex, columnId, value)
+ : undefined;
+ },
+ [table]
+ );
+
+ const onKeyDown = useCallback(
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
+ if (!selectedCell) return;
+
+ const { code } = event;
+
+ const commandCodes: {
+ [key: string]: [0, 1] | [1, 0] | [0, -1] | [-1, 0];
+ } = {
+ Tab: [0, 1],
+ Enter: [1, 0],
+ };
+
+ const navigationCodes: {
+ [key: string]: [0, 1] | [1, 0] | [0, -1] | [-1, 0];
+ } = {
+ ArrowRight: [0, 1],
+ ArrowLeft: [0, -1],
+ ArrowDown: [1, 0],
+ ArrowUp: [-1, 0],
+ };
+
+ const lastRow = table.getRowModel().rows.length - 1;
+ const lastColumn =
+ table.getVisibleLeafColumns().length - 1 - (withSelectableRows ? 1 : 0);
+
+ const navigate = (delta: number[], tabWrap = false): number[] => {
+ const x0 = selectedCell?.column || 0;
+ const y0 = selectedCell?.row || 0;
+
+ let x1 = x0 + delta[1];
+ let y1 = y0 + delta[0];
+
+ if (tabWrap) {
+ // wrap to the next row if we're on the last column
+ if (x1 > lastColumn) {
+ x1 = 0;
+ y1++;
+ }
+ // don't wrap to the next row if we're on the last row
+ if (y1 > lastRow) {
+ x1 = x0;
+ y1 = y0;
+ }
+ } else {
+ x1 = clip(x1, 0, lastColumn);
+ }
+
+ y1 = clip(y1, 0, lastRow);
+
+ return [x1, y1];
+ };
+
+ if (code in commandCodes) {
+ // enter and tab work even if we're editing
+ event.preventDefault();
+ const [x1, y1] = navigate(commandCodes[code], code === "Tab");
+ setSelectedCell({
+ row: y1,
+ column: x1,
+ });
+
+ if (isEditing) {
+ focusOnSelectedCell();
+ setIsEditing(false);
+ }
+ } else if (code in navigationCodes) {
+ // arrow key navigation should't work if we're editing
+ if (isEditing) return;
+ event.preventDefault();
+ const [x1, y1] = navigate(navigationCodes[code], code === "Tab");
+ setIsEditing(false);
+ setSelectedCell({
+ row: y1,
+ column: x1,
+ });
+ } else if (
+ !isEditing &&
+ selectedCell &&
+ isColumnEditable(selectedCell.column)
+ ) {
+ // any other key activates editing if the column is editable and a cell is selected
+ setIsEditing(true);
+ }
+ },
+ [
+ focusOnSelectedCell,
+ isColumnEditable,
+ isEditing,
+ selectedCell,
+ setSelectedCell,
+ table,
+ withSelectableRows,
+ ]
+ );
+
+ // reset the selected cell when the table data changes
+ useEffect(() => {
+ setSelectedCell(null);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [
+ editMode,
+ pagination.pageIndex,
+ pagination.pageSize,
+ columnOrder,
+ columnVisibility,
+ ]);
+
useEffect(() => {
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -137,76 +365,107 @@ const Table = <T extends object>({
}, [rowSelection, onSelectedRowsChange]);
const rows = table.getRowModel().rows;
+ const rowsAreClickable = !editMode && typeof onRowClick === "function";
+
+ const rowVirtualizer = useVirtual({
+ parentRef: tableContainerRef,
+ size: rows.length,
+ overscan: 10,
+ });
+
+ // const columnVirtualizer = useVirtual({
+ // horizontal: true,
+ // size: table.getVisibleLeafColumns().length,
+ // parentRef: tableContainerRef,
+ // estimateSize: useCallback(() => 250, []),
+ // overscan: 5,
+ // });
+
+ const { virtualItems: virtualRows, totalSize: totalRows } = rowVirtualizer;
+
+ const virtualPaddingTop =
+ virtualRows.length > 0 ? virtualRows?.[0]?.start || 0 : 0;
+ const virutalPaddingBottom =
+ virtualRows.length > 0
+ ? totalRows - (virtualRows?.[virtualRows.length - 1]?.end || 0)
+ : 0;
+
const defaultBackground = useColor("white");
- const rowBackground = useColor("gray.50");
const borderColor = useColor("gray.200");
+ const rowBackground = useColor("gray.50");
return (
- <>
- <Box w="full" h="full">
- {(withColumnOrdering || withFilters || withSelectableRows) && (
- <Header
- actions={actions}
- columnAccessors={columnAccessors}
- columnOrder={columnOrder}
- columns={table.getAllLeafColumns()}
- selectedRows={selectedRows}
- setColumnOrder={setColumnOrder}
- pagination={pagination}
- withColumnOrdering={withColumnOrdering}
- withFilters={withFilters}
- withPagination={withPagination}
- withSelectableRows={withSelectableRows}
- />
- )}
- <Box h="full" overflow="scroll" style={{ contain: "strict" }}>
- <Grid
- w="full"
- gridTemplateColumns={withColumnOrdering ? "auto 1fr auto" : "1fr"}
- >
- {/* Pinned left columns */}
- {withColumnOrdering ? (
- <ChakraTable
- bg={defaultBackground}
- borderRightColor={borderColor}
- borderRightStyle="solid"
- borderRightWidth={4}
- position="sticky"
- left={0}
- >
- <Thead h={10}>
- {table.getLeftHeaderGroups().map((headerGroup) => (
- <Tr key={headerGroup.id}>
- {headerGroup.headers.map((header) => {
- // TODO: improve this
- const sortable =
- withSimpleSorting &&
- "accessorKey" in header.column.columnDef &&
- header.column.columnDef.enableSorting !== false;
- const sorted = isSorted(
- // @ts-ignore
- header.column.columnDef?.accessorKey ?? ""
- );
- return (
- <Th
- key={header.id}
- layout
- onClick={
- sortable
- ? () =>
- toggleSortBy(
- // @ts-ignore
- header.column.columnDef?.accessorKey ?? ""
- )
- : undefined
- }
- cursor={sortable ? "pointer" : undefined}
- transition={spring}
- colSpan={header.colSpan}
- px={4}
- py={2}
- whiteSpace="nowrap"
- >
+ <VStack w="full" h="full" spacing={0}>
+ {(withColumnOrdering || withFilters || withSelectableRows) && (
+ <Header
+ actions={actions}
+ columnAccessors={columnAccessors}
+ columnOrder={columnOrder}
+ columns={table.getAllLeafColumns()}
+ editMode={editMode}
+ selectedRows={selectedRows}
+ setColumnOrder={setColumnOrder}
+ setEditMode={setEditMode}
+ pagination={pagination}
+ withInlineEditing={withInlineEditing}
+ withColumnOrdering={withColumnOrdering}
+ withFilters={withFilters}
+ withPagination={withPagination}
+ withSelectableRows={withSelectableRows}
+ />
+ )}
+ <Box
+ w="full"
+ h="full"
+ overflow="scroll"
+ style={{ contain: "strict" }}
+ ref={tableContainerRef}
+ onKeyDown={editMode ? onKeyDown : undefined}
+ >
+ <Grid
+ w="full"
+ gridTemplateColumns={withColumnOrdering ? "auto 1fr auto" : "1fr"}
+ >
+ {/* Pinned left columns */}
+ {withColumnOrdering ? (
+ <ChakraTable
+ bg={defaultBackground}
+ borderRightColor={borderColor}
+ borderRightStyle="solid"
+ borderRightWidth={4}
+ position="sticky"
+ left={0}
+ >
+ <Thead>
+ {table.getLeftHeaderGroups().map((headerGroup) => (
+ <Tr key={headerGroup.id} h={10}>
+ {headerGroup.headers.map((header) => {
+ const accessorKey = getAccessorKey(
+ header.column.columnDef
+ );
+ const sortable =
+ withSimpleSorting &&
+ accessorKey &&
+ header.column.columnDef.enableSorting !== false;
+ const sorted = isSorted(accessorKey ?? "");
+
+ return (
+ <Th
+ key={header.id}
+ // layout
+ onClick={
+ sortable && !editMode
+ ? () => toggleSortBy(accessorKey ?? "")
+ : undefined
+ }
+ cursor={sortable ? "pointer" : undefined}
+ // transition={spring}
+ colSpan={header.colSpan}
+ px={4}
+ py={2}
+ whiteSpace="nowrap"
+ >
+ {header.isPlaceholder ? null : (
<Flex
justify="flex-start"
align="center"
@@ -227,97 +486,91 @@ const Table = <T extends object>({
) : null}
</chakra.span>
</Flex>
- </Th>
- );
- })}
- </Tr>
- ))}
- </Thead>
- <Tbody>
- <AnimatePresence>
- {rows.map((row) => {
- return (
- <Tr
- key={row.id}
- exit={{ opacity: 0 }}
- layout
- transition={spring}
- onClick={() => {
- if (typeof onRowClick === "function") {
- onRowClick(row.original);
- }
- }}
- _hover={{
- cursor:
- typeof onRowClick === "function"
- ? "pointer"
- : undefined,
- background: rowBackground,
- }}
- >
- {row.getLeftVisibleCells().map((cell) => {
- return (
- <Td
- key={cell.id}
- layout
- transition={spring}
- fontSize="sm"
- px={4}
- py={2}
- >
- {flexRender(
- cell.column.columnDef.cell,
- cell.getContext()
- )}
- </Td>
- );
- })}
- </Tr>
+ )}
+ </Th>
);
})}
- </AnimatePresence>
- </Tbody>
- </ChakraTable>
- ) : null}
-
- {/* Unpinned columns */}
- <ChakraTable>
- <Thead h={10}>
- {(withColumnOrdering
- ? table.getCenterHeaderGroups()
- : table.getHeaderGroups()
- ).map((headerGroup) => (
- <Tr key={headerGroup.id}>
- {headerGroup.headers.map((header) => {
- const sortable =
- withSimpleSorting &&
- "accessorKey" in header.column.columnDef;
- const sorted = isSorted(
- // @ts-ignore
- header.column.columnDef?.accessorKey ?? ""
- );
+ </Tr>
+ ))}
+ </Thead>
+ <Tbody>
+ {virtualPaddingTop > 0 && (
+ <Tr>
+ <Td style={{ height: `${virtualPaddingTop}px` }} />
+ </Tr>
+ )}
+ {/* <AnimatePresence> */}
+ {virtualRows.map((virtualRow) => {
+ const row = rows[virtualRow.index] as RowType<T>;
- return (
- <Th
- key={header.id}
- colSpan={header.colSpan}
- onClick={
- sortable
- ? () =>
- toggleSortBy(
- // @ts-ignore
- header.column.columnDef?.accessorKey ?? ""
- )
- : undefined
- }
- cursor={sortable ? "pointer" : undefined}
- layout
- transition={spring}
- px={4}
- py={3}
- w={header.getSize()}
- whiteSpace="nowrap"
- >
+ return (
+ <Row
+ key={row.id}
+ borderColor={borderColor}
+ backgroundColor={rowBackground}
+ editableComponents={editableComponents}
+ isEditing={isEditing}
+ isEditMode={editMode}
+ isFrozenColumn
+ selectedCell={selectedCell}
+ // @ts-ignore
+ row={row}
+ withColumnOrdering={withColumnOrdering}
+ onCellClick={onCellClick}
+ onCellUpdate={onCellEditUpdate}
+ onRowClick={
+ onRowClick ? () => onRowClick(row.original) : undefined
+ }
+ />
+ );
+ })}
+ {/* </AnimatePresence> */}
+ {virutalPaddingBottom > 0 && (
+ <Tr>
+ <Td style={{ height: `${virutalPaddingBottom}px` }} />
+ </Tr>
+ )}
+ </Tbody>
+ </ChakraTable>
+ ) : null}
+
+ {/* Unpinned columns */}
+ <ChakraTable>
+ <Thead>
+ {(withColumnOrdering
+ ? table.getCenterHeaderGroups()
+ : table.getHeaderGroups()
+ ).map((headerGroup) => (
+ <Tr key={headerGroup.id} h={10}>
+ {headerGroup.headers.map((header) => {
+ const accessorKey = getAccessorKey(header.column.columnDef);
+ const sortable =
+ withSimpleSorting &&
+ accessorKey &&
+ header.column.columnDef.enableSorting !== false;
+ const sorted = isSorted(accessorKey ?? "");
+
+ return (
+ <Th
+ key={header.id}
+ colSpan={header.colSpan}
+ onClick={
+ sortable
+ ? () => toggleSortBy(accessorKey ?? "")
+ : undefined
+ }
+ borderRightColor={borderColor}
+ borderRightStyle="solid"
+ borderRightWidth={editMode ? 1 : undefined}
+ cursor={sortable ? "pointer" : undefined}
+ // layout
+ // transition={spring}
+ px={4}
+ py={3}
+ w={header.getSize()}
+ whiteSpace="nowrap"
+ >
+ {header.isPlaceholder ? null : (
<Flex
justify="flex-start"
align="center"
@@ -338,161 +591,70 @@ const Table = <T extends object>({
) : null}
</chakra.span>
</Flex>
- </Th>
- );
- })}
- </Tr>
- ))}
- </Thead>
- <Tbody>
- <AnimatePresence>
- {rows.map((row) => {
- return (
- <Tr
- key={row.id}
- exit={{ opacity: 0 }}
- layout
- transition={spring}
- onClick={() => {
- if (typeof onRowClick === "function") {
- onRowClick(row.original);
- }
- }}
- _hover={{
- cursor:
- typeof onRowClick === "function"
- ? "pointer"
- : undefined,
- background: rowBackground,
- }}
- >
- {(withColumnOrdering
- ? row.getCenterVisibleCells()
- : row.getVisibleCells()
- ).map((cell) => {
- return (
- <Td
- key={cell.id}
- fontSize="sm"
- layout
- transition={spring}
- px={4}
- py={withColumnOrdering ? 3 : 2}
- whiteSpace="nowrap"
- >
- {flexRender(
- cell.column.columnDef.cell,
- cell.getContext()
- )}
- </Td>
- );
- })}
- </Tr>
+ )}
+ </Th>
);
})}
- </AnimatePresence>
- </Tbody>
- </ChakraTable>
+ </Tr>
+ ))}
+ </Thead>
+ <Tbody>
+ {virtualPaddingTop > 0 && (
+ <Tr>
+ <Td style={{ height: `${virtualPaddingTop}px` }} />
+ </Tr>
+ )}
+ {/* <AnimatePresence> */}
+ {virtualRows.map((virtualRow) => {
+ const row = rows[virtualRow.index] as RowType<T>;
- {/* Pinned right columns
- {withColumnOrdering ? (
- <ChakraTable
- bg={defaultBackground}
- borderLeftColor={borderColor}
- borderLeftStyle="solid"
- borderLeftWidth={4}
- // position="sticky"
- // right={0}
- >
- <Thead h={10}>
- {table.getRightHeaderGroups().map((headerGroup) => (
- <Tr key={headerGroup.id}>
- {headerGroup.headers.map((header) => {
- return (
- <Th
- key={header.id}
- layout
- transition={spring}
- colSpan={header.colSpan}
- px={4}
- py={3}
- >
- {flexRender(
- header.column.columnDef.header,
- header.getContext()
- )}
- </Th>
- );
- })}
- </Tr>
- ))}
- </Thead>
- <Tbody>
- <AnimatePresence>
- {rows.map((row) => {
- return (
- <Tr
- key={row.id}
- exit={{ opacity: 0 }}
- layout
- transition={spring}
- onClick={() => {
- if (typeof onRowClick === "function") {
- onRowClick(row.original);
- }
- }}
- _hover={{
- cursor:
- typeof onRowClick === "function"
- ? "pointer"
- : undefined,
- background: rowBackground,
- }}
- >
- {row.getRightVisibleCells().map((cell) => {
- return (
- <Td
- key={cell.id}
- layout
- transition={spring}
- fontSize="sm"
- px={4}
- py={2}
- >
- {flexRender(
- cell.column.columnDef.cell,
- cell.getContext()
- )}
- </Td>
- );
- })}
- </Tr>
- );
- })}
- </AnimatePresence>
- </Tbody>
- </ChakraTable>
- ) : null} */}
- </Grid>
- </Box>
+ return (
+ <Row
+ key={row.id}
+ borderColor={borderColor}
+ backgroundColor={rowBackground}
+ // @ts-ignore
+ editableComponents={editableComponents}
+ isEditing={isEditing}
+ isEditMode={editMode}
+ pinnedColumns={
+ columnPinning?.left
+ ? columnPinning.left?.length -
+ (withSelectableRows ? 1 : 0)
+ : 0
+ }
+ selectedCell={selectedCell}
+ // @ts-ignore
+ row={row}
+ rowIsClickable={rowsAreClickable}
+ withColumnOrdering={withColumnOrdering}
+ onCellClick={onCellClick}
+ onCellUpdate={onCellEditUpdate}
+ onRowClick={
+ rowsAreClickable
+ ? () => onRowClick(row.original)
+ : undefined
+ }
+ />
+ );
+ })}
+ {/* </AnimatePresence> */}
+ {virutalPaddingBottom > 0 && (
+ <Tr>
+ <Td style={{ height: `${virutalPaddingBottom}px` }} />
+ </Tr>
+ )}
+ </Tbody>
+ </ChakraTable>
+ </Grid>
</Box>
{withPagination && (
<Pagination {...pagination} colorScheme={colorScheme} />
)}
- </>
+ </VStack>
);
};
-const Th = motion(ChakraTh);
-const Tr = motion(ChakraTr);
-const Td = motion(ChakraTd);
-
-const spring = {
- type: "spring",
- damping: 10,
- stiffness: 30,
-};
-
function getRowSelectionColumn<T>(): ColumnDef<T> {
return {
id: "select",
diff --git a/apps/carbon/app/components/Table/components/Actions/Actions.tsx b/apps/carbon/app/components/Table/components/Actions/Actions.tsx
index c1db3754c9..7f0de14862 100644
--- a/apps/carbon/app/components/Table/components/Actions/Actions.tsx
+++ b/apps/carbon/app/components/Table/components/Actions/Actions.tsx
@@ -18,7 +18,7 @@ const Actions = <T extends Object>({
leftIcon={<IoMdCheckboxOutline />}
disabled={selectedRows.length === 0}
colorScheme={selectedRows.length === 0 ? "gray" : "brand"}
- variant={selectedRows.length === 0 ? "ghost" : "solid"}
+ variant="ghost"
>
Actions
</MenuButton>
diff --git a/apps/carbon/app/components/Table/components/Animations/Animations.tsx b/apps/carbon/app/components/Table/components/Animations/Animations.tsx
new file mode 100644
index 0000000000..aca3212709
--- /dev/null
+++ b/apps/carbon/app/components/Table/components/Animations/Animations.tsx
@@ -0,0 +1,16 @@
+import {
+ Td as ChakraTd,
+ Th as ChakraTh,
+ Tr as ChakraTr,
+} from "@chakra-ui/react";
+import { motion } from "framer-motion";
+
+export const spring = {
+ type: "spring",
+ damping: 10,
+ stiffness: 30,
+};
+
+export const Th = motion(ChakraTh);
+export const Tr = motion(ChakraTr);
+export const Td = motion(ChakraTd);
diff --git a/apps/carbon/app/components/Table/components/Animations/index.ts b/apps/carbon/app/components/Table/components/Animations/index.ts
new file mode 100644
index 0000000000..a543e1adf1
--- /dev/null
+++ b/apps/carbon/app/components/Table/components/Animations/index.ts
@@ -0,0 +1,3 @@
+import { Td, Th, Tr, spring } from "./Animations";
+
+export { Td, Th, Tr, spring };
diff --git a/apps/carbon/app/components/Table/components/Cell/Cell.tsx b/apps/carbon/app/components/Table/components/Cell/Cell.tsx
new file mode 100644
index 0000000000..4606528adf
--- /dev/null
+++ b/apps/carbon/app/components/Table/components/Cell/Cell.tsx
@@ -0,0 +1,122 @@
+import {
+ Box,
+ HStack,
+ Popover,
+ PopoverAnchor,
+ PopoverBody,
+ PopoverContent,
+ Td,
+} from "@chakra-ui/react";
+import type { Cell as CellType } from "@tanstack/react-table";
+import { flexRender } from "@tanstack/react-table";
+import { useMovingCellRef } from "../../hooks/useMovingCellRef";
+import { memo } from "react";
+// import { Td, spring } from "../Animations";
+import type { EditableTableCellComponent } from "../../types";
+import { getAccessorKey } from "../../utils";
+
+type CellProps<T> = {
+ borderColor: string;
+ cell: CellType<T, unknown>;
+ columnIndex: number;
+ editableComponents: Record<string, EditableTableCellComponent<T>>;
+ isSelected: boolean;
+ isEditing: boolean;
+ isEditMode: boolean;
+ onClick?: () => void;
+ onUpdate?: (value: unknown) => void;
+};
+
+const Cell = <T extends object>({
+ borderColor,
+ cell,
+ columnIndex,
+ editableComponents,
+ isSelected,
+ isEditing,
+ isEditMode,
+ onClick,
+ onUpdate,
+}: CellProps<T>) => {
+ const { ref, tabIndex, onFocus } = useMovingCellRef(isSelected);
+ const accessorKey = getAccessorKey(cell.column.columnDef);
+
+ const hasEditableTableCellComponent =
+ accessorKey !== undefined && accessorKey in editableComponents;
+
+ return (
+ <Td
+ ref={ref}
+ data-row={cell.row.index}
+ data-column={columnIndex}
+ // layout
+ // transition={spring}
+ tabIndex={tabIndex}
+ bgColor={
+ isEditMode && !hasEditableTableCellComponent ? "gray.50" : undefined
+ }
+ borderRightColor={borderColor}
+ borderRightStyle="solid"
+ borderRightWidth={isEditMode ? 1 : undefined}
+ boxShadow={
+ isSelected
+ ? "inset 0 0 0 3px var(--chakra-ui-focus-ring-color)"
+ : undefined
+ }
+ fontSize="sm"
+ outline="none"
+ px={4}
+ py={2}
+ whiteSpace="nowrap"
+ onClick={onClick}
+ onFocus={onFocus}
+ >
+ <Box ref={ref}>
+ {isSelected && isEditing && hasEditableTableCellComponent ? (
+ <Popover
+ isOpen
+ onOpen={() => console.log("opened")}
+ onClose={() => console.log("closed")}
+ closeOnBlur
+ isLazy
+ >
+ <PopoverAnchor>
+ <Box>
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+ </Box>
+ </PopoverAnchor>
+
+ <PopoverContent>
+ <PopoverBody>
+ <HStack spacing={2}>
+ {editableComponents[accessorKey!]({
+ accessorKey,
+ value: cell.getValue(),
+ row: cell.row.original,
+ onUpdate: onUpdate
+ ? onUpdate
+ : () => {
+ console.error("failed to pass an onUpdate function");
+ },
+ })}
+ </HStack>
+ </PopoverBody>
+ </PopoverContent>
+ </Popover>
+ ) : (
+ flexRender(cell.column.columnDef.cell, cell.getContext())
+ )}
+ </Box>
+ </Td>
+ );
+};
+
+export const MemoizedCell = memo(
+ Cell,
+ (prev, next) =>
+ next.cell === prev.cell &&
+ next.isSelected === prev.isSelected &&
+ next.isEditing === prev.isEditing &&
+ next.isEditMode === prev.isEditMode &&
+ next.cell.column.columnDef.id !== "select"
+);
diff --git a/apps/carbon/app/components/Table/components/Cell/index.ts b/apps/carbon/app/components/Table/components/Cell/index.ts
new file mode 100644
index 0000000000..619f44dbca
--- /dev/null
+++ b/apps/carbon/app/components/Table/components/Cell/index.ts
@@ -0,0 +1,3 @@
+import { MemoizedCell as Cell } from "./Cell";
+
+export default Cell;
diff --git a/apps/carbon/app/components/Table/components/Columns/Columns.tsx b/apps/carbon/app/components/Table/components/Columns/Columns.tsx
index 47655e8efa..74d0c0473f 100644
--- a/apps/carbon/app/components/Table/components/Columns/Columns.tsx
+++ b/apps/carbon/app/components/Table/components/Columns/Columns.tsx
@@ -37,7 +37,7 @@ const Columns = <T extends object>({
setColumnOrder,
}: ColumnsProps<T>) => {
return (
- <Popover placement="bottom">
+ <Popover placement="bottom" closeOnBlur>
<PopoverTrigger>
<Button variant="ghost" leftIcon={<BsLayoutThreeColumns />}>
Columns
@@ -83,11 +83,17 @@ const Columns = <T extends object>({
<IconButton
aria-label="Toggle column"
icon={column.getIsPinned() ? <BsPinFill /> : <BsPin />}
- onClick={() =>
- column.getIsPinned()
- ? column.pin(false)
- : column.pin("left")
- }
+ onClick={(e) => {
+ if (column.getIsPinned()) {
+ column.pin(false);
+ } else {
+ column.pin("left");
+ // when a column is pinned, we assure that it's visible
+ if (!column.getIsVisible()) {
+ column.getToggleVisibilityHandler()(e);
+ }
+ }
+ }}
variant="ghost"
/>
<IconButton
diff --git a/apps/carbon/app/components/Table/components/Header/Header.tsx b/apps/carbon/app/components/Table/components/Header/Header.tsx
index 3e42570658..afb9c5ea3b 100644
--- a/apps/carbon/app/components/Table/components/Header/Header.tsx
+++ b/apps/carbon/app/components/Table/components/Header/Header.tsx
@@ -1,6 +1,8 @@
import { useColor } from "@carbon/react";
-import { HStack } from "@chakra-ui/react";
+import { Button, HStack } from "@chakra-ui/react";
import type { Column, ColumnOrderState } from "@tanstack/react-table";
+import { BsFillCheckCircleFill } from "react-icons/bs";
+import { MdOutlineEditNote } from "react-icons/md";
import type { TableAction } from "../../types";
import Actions from "../Actions";
import Columns from "../Columns";
@@ -14,11 +16,14 @@ type HeaderProps<T> = {
columnAccessors: Record<string, string>;
columnOrder: ColumnOrderState;
columns: Column<T, unknown>[];
+ editMode: boolean;
pagination: PaginationProps;
selectedRows: T[];
setColumnOrder: (newOrder: ColumnOrderState) => void;
+ setEditMode: (editMode: boolean) => void;
withColumnOrdering: boolean;
withFilters: boolean;
+ withInlineEditing: boolean;
withPagination: boolean;
withSelectableRows: boolean;
};
@@ -28,11 +33,14 @@ const Header = <T extends object>({
columnAccessors,
columnOrder,
columns,
+ editMode,
pagination,
selectedRows,
setColumnOrder,
+ setEditMode,
withColumnOrdering,
withFilters,
+ withInlineEditing,
withPagination,
withSelectableRows,
}: HeaderProps<T>) => {
@@ -52,6 +60,25 @@ const Header = <T extends object>({
{withSelectableRows && actions.length > 0 && (
<Actions actions={actions} selectedRows={selectedRows} />
)}
+ {withInlineEditing &&
+ (editMode ? (
+ <Button
+ colorScheme="brand"
+ leftIcon={<BsFillCheckCircleFill />}
+ variant="solid"
+ onClick={() => setEditMode(false)}
+ >
+ Finish Editing
+ </Button>
+ ) : (
+ <Button
+ leftIcon={<MdOutlineEditNote />}
+ variant="ghost"
+ onClick={() => setEditMode(true)}
+ >
+ Edit Mode
+ </Button>
+ ))}
</HStack>
<HStack spacing={2}>
{withFilters && (
diff --git a/apps/carbon/app/components/Table/components/Row/Row.tsx b/apps/carbon/app/components/Table/components/Row/Row.tsx
new file mode 100644
index 0000000000..11aab2d15c
--- /dev/null
+++ b/apps/carbon/app/components/Table/components/Row/Row.tsx
@@ -0,0 +1,102 @@
+import type { Row as RowType } from "@tanstack/react-table";
+import { Tr } from "@chakra-ui/react";
+// import { Tr, spring } from "../Animations";
+import Cell from "../Cell";
+import type { EditableTableCellComponent, Position } from "../../types";
+import { useColor } from "@carbon/react";
+
+type RowProps<T> = {
+ borderColor: string;
+ backgroundColor: string;
+ editableComponents: Record<string, EditableTableCellComponent<T>>;
+ isEditing: boolean;
+ isEditMode: boolean;
+ isFrozenColumn?: boolean;
+ pinnedColumns?: number;
+ selectedCell: Position;
+ row: RowType<T>;
+ rowIsClickable?: boolean;
+ withColumnOrdering: boolean;
+ onCellClick: (row: number, column: number) => void;
+ onCellUpdate: (row: number, columnId: string) => (value: unknown) => void;
+ onRowClick?: () => void;
+};
+
+const Row = <T extends object>({
+ borderColor,
+ backgroundColor,
+ editableComponents,
+ isEditing,
+ isEditMode,
+ isFrozenColumn = false,
+ pinnedColumns = 0,
+ row,
+ rowIsClickable = false,
+ selectedCell,
+ withColumnOrdering,
+ onCellClick,
+ onCellUpdate,
+ onRowClick,
+}: RowProps<T>) => {
+ const frozenBackgroundColor = useColor("white");
+ return (
+ <Tr
+ key={row.id}
+ bg={isFrozenColumn ? frozenBackgroundColor : undefined}
+ // exit={{ opacity: 0 }}
+ // layout
+ // transition={spring}
+ onClick={onRowClick}
+ _hover={{
+ cursor: rowIsClickable ? "pointer" : undefined,
+ backgroundColor,
+ }}
+ >
+ {(isFrozenColumn
+ ? row.getLeftVisibleCells()
+ : withColumnOrdering
+ ? row.getCenterVisibleCells()
+ : row.getVisibleCells()
+ ).map((cell, columnIndex) => {
+ const isSelected = isFrozenColumn
+ ? selectedCell?.row === cell.row.index &&
+ selectedCell?.column === columnIndex - 1
+ : selectedCell?.row === cell.row.index &&
+ selectedCell?.column === columnIndex + pinnedColumns;
+
+ return (
+ <Cell
+ key={cell.id}
+ borderColor={borderColor}
+ // @ts-ignore
+ cell={cell}
+ columnIndex={columnIndex}
+ // @ts-ignore
+ editableComponents={editableComponents}
+ isSelected={isSelected}
+ isEditing={isEditing}
+ isEditMode={isEditMode}
+ onClick={
+ isEditMode
+ ? () =>
+ onCellClick(
+ cell.row.index,
+ isFrozenColumn
+ ? columnIndex - 1
+ : columnIndex + pinnedColumns
+ )
+ : undefined
+ }
+ onUpdate={
+ isEditMode
+ ? onCellUpdate(cell.row.index, cell.column.id)
+ : undefined
+ }
+ />
+ );
+ })}
+ </Tr>
+ );
+};
+
+export default Row;
diff --git a/apps/carbon/app/components/Table/components/Row/index.ts b/apps/carbon/app/components/Table/components/Row/index.ts
new file mode 100644
index 0000000000..2e964c396d
--- /dev/null
+++ b/apps/carbon/app/components/Table/components/Row/index.ts
@@ -0,0 +1,3 @@
+import Row from "./Row";
+
+export default Row;
diff --git a/apps/carbon/app/components/Table/components/Sort/Sort.tsx b/apps/carbon/app/components/Table/components/Sort/Sort.tsx
index 61effb563e..ae3e7f5629 100644
--- a/apps/carbon/app/components/Table/components/Sort/Sort.tsx
+++ b/apps/carbon/app/components/Table/components/Sort/Sort.tsx
@@ -36,20 +36,21 @@ const Sort = ({ columnAccessors }: SortProps) => {
toggleSortBy,
toggleSortByDirection,
} = useSort();
+ const hasNoSorts = sorts.length === 0;
return (
- <Popover placement="bottom">
+ <Popover placement="bottom" closeOnBlur>
<PopoverTrigger>
<Button
- colorScheme={sorts.length === 0 ? undefined : "brand"}
- variant={sorts.length === 0 ? "ghost" : "solid"}
+ colorScheme={hasNoSorts ? undefined : "brand"}
+ variant={hasNoSorts ? "ghost" : "solid"}
leftIcon={<BsListUl />}
>
- {sorts.length === 0 ? "Sort" : "Sorted"}
+ {hasNoSorts ? "Sort" : "Sorted"}
</Button>
</PopoverTrigger>
<PopoverContent w={420} boxShadow="xl">
- {sorts.length === 0 && (
+ {hasNoSorts && (
<PopoverHeader>
<Text fontSize="sm">No sorts applied to this view</Text>
<Text fontSize="xs" color="gray.500">
@@ -58,7 +59,7 @@ const Sort = ({ columnAccessors }: SortProps) => {
</PopoverHeader>
)}
<PopoverArrow />
- {sorts.length > 0 && (
+ {!hasNoSorts && (
<PopoverBody>
<List
as={Reorder.Group}
diff --git a/apps/carbon/app/components/Table/components/Sort/useSort.tsx b/apps/carbon/app/components/Table/components/Sort/useSort.tsx
index e136202cfc..e92dbf9c52 100644
--- a/apps/carbon/app/components/Table/components/Sort/useSort.tsx
+++ b/apps/carbon/app/components/Table/components/Sort/useSort.tsx
@@ -41,11 +41,11 @@ export function useSort() {
if (existingSort.includes(sortAsc)) {
setParams({
- sort: existingSort.filter((s) => s !== sortAsc).concat(sortDesc),
+ sort: existingSort.map((s) => (s === sortAsc ? sortDesc : s)),
});
} else if (existingSort.includes(sortDesc)) {
setParams({
- sort: existingSort.filter((s) => s !== sortDesc).concat(sortAsc),
+ sort: existingSort.map((s) => (s === sortDesc ? sortAsc : s)),
});
}
};
diff --git a/apps/carbon/app/components/Table/components/index.ts b/apps/carbon/app/components/Table/components/index.ts
index f19bbb0f51..970bf889a1 100644
--- a/apps/carbon/app/components/Table/components/index.ts
+++ b/apps/carbon/app/components/Table/components/index.ts
@@ -1,6 +1,21 @@
+import { Td, Th, Tr, spring } from "./Animations";
+import Cell from "./Cell";
import Header from "./Header";
import IndeterminateCheckbox from "./IndeterminateCheckbox";
import { Pagination, usePagination } from "./Pagination";
+import Row from "./Row";
import { useSort } from "./Sort";
-export { Header, IndeterminateCheckbox, Pagination, usePagination, useSort };
+export {
+ Cell,
+ Header,
+ IndeterminateCheckbox,
+ Pagination,
+ Row,
+ Tr,
+ Td,
+ Th,
+ spring,
+ usePagination,
+ useSort,
+};
diff --git a/apps/carbon/app/components/Table/hooks/useMovingCellRef.tsx b/apps/carbon/app/components/Table/hooks/useMovingCellRef.tsx
new file mode 100644
index 0000000000..7de9b0f6cd
--- /dev/null
+++ b/apps/carbon/app/components/Table/hooks/useMovingCellRef.tsx
@@ -0,0 +1,33 @@
+import { useCallback, useState } from "react";
+import { scrollIntoView } from "../utils";
+
+// https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_roving_tabindex
+export function useMovingCellRef(isSelected: boolean) {
+ // https://www.w3.org/TR/wai-aria-practices-1.1/#gridNav_focus
+ const [isChildFocused, setIsChildFocused] = useState(false);
+
+ if (isChildFocused && !isSelected) {
+ setIsChildFocused(false);
+ }
+
+ const ref = useCallback((cell: HTMLElement | null) => {
+ if (cell === null) return;
+ scrollIntoView(cell);
+ if (cell.contains(document.activeElement)) return;
+ cell.focus({ preventScroll: true });
+ }, []);
+
+ function onFocus(event: React.FocusEvent<HTMLElement>) {
+ if (event.target !== event.currentTarget) {
+ setIsChildFocused(true);
+ }
+ }
+
+ const isFocused = isSelected && !isChildFocused;
+
+ return {
+ ref: isSelected ? ref : undefined,
+ tabIndex: isFocused ? 0 : -1,
+ onFocus: isSelected ? onFocus : undefined,
+ };
+}
diff --git a/apps/carbon/app/components/Table/types.ts b/apps/carbon/app/components/Table/types.ts
index 473bbe3da2..b7f4799e5b 100644
--- a/apps/carbon/app/components/Table/types.ts
+++ b/apps/carbon/app/components/Table/types.ts
@@ -1,3 +1,25 @@
+export type EditableTableCellComponent<TData extends unknown> = (props: {
+ accessorKey: string;
+ row: TData;
+ value: unknown;
+ onUpdate: (value: unknown) => void;
+}) => JSX.Element;
+
+export type EditableTableCellComponentProps<T> = {
+ value: unknown;
+ row: T;
+ accessorKey: string;
+ onUpdate: (value: unknown) => void;
+};
+
+declare module "@tanstack/react-table" {
+ interface TableMeta<TData extends unknown> {
+ editableComponents?: Record<string, EditableTableCellComponent<TData>>;
+ updateData?: (rowIndex: number, columnId: string, value: unknown) => void;
+ }
+}
+
+export type Position = null | { row: number; column: number };
export interface TableAction<T> {
label: string;
onClick: (rows: T[]) => void;
diff --git a/apps/carbon/app/components/Table/utils.ts b/apps/carbon/app/components/Table/utils.ts
new file mode 100644
index 0000000000..f990706293
--- /dev/null
+++ b/apps/carbon/app/components/Table/utils.ts
@@ -0,0 +1,29 @@
+import type { ColumnDef } from "@tanstack/react-table";
+
+export function getAccessorKey<T>(columnDef: ColumnDef<T, unknown>) {
+ return "accessorKey" in columnDef
+ ? columnDef?.accessorKey.toString()
+ : undefined;
+}
+
+export function updateNestedProperty(
+ obj: object,
+ path: string | string[],
+ value: unknown
+): unknown {
+ if (typeof path == "string")
+ return updateNestedProperty(obj, path.split("_"), value);
+ else if (path.length == 1 && value !== undefined)
+ // @ts-ignore
+ return (obj[path[0]] = value);
+ else if (path.length == 0) return obj;
+ // @ts-ignore
+ else return updateNestedProperty(obj[path[0]], path.slice(1), value);
+}
+
+export function scrollIntoView(element: HTMLElement | undefined | null) {
+ element?.scrollIntoView({
+ inline: "nearest",
+ block: "nearest",
+ });
+}
diff --git a/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoriesTable/AttributesCategoriesTable.tsx b/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoriesTable/AttributesCategoriesTable.tsx
index 3a22e54595..b08d7400c8 100644
--- a/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoriesTable/AttributesCategoriesTable.tsx
+++ b/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoriesTable/AttributesCategoriesTable.tsx
@@ -1,10 +1,11 @@
import { ActionMenu } from "@carbon/react";
import {
+ Badge,
Button,
+ ButtonGroup,
Flex,
+ IconButton,
MenuItem,
- Tag,
- TagLabel,
useDisclosure,
VisuallyHidden,
} from "@chakra-ui/react";
@@ -12,7 +13,7 @@ import { Link, useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
import { BiAddToQueue } from "react-icons/bi";
-import { BsPencilSquare, BsListUl } from "react-icons/bs";
+import { BsPencilSquare, BsListUl, BsPlus } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { Table } from "~/components";
import { usePermissions } from "~/hooks";
@@ -53,15 +54,25 @@ const AttributeCategoriesTable = memo(
{
header: "Attributes",
cell: ({ row }) => (
- <Button
- as={Link}
- to={`/app/users/attributes/list/${row.original.id}`}
- >
- {Array.isArray(row.original.userAttribute)
- ? row.original.userAttribute?.length ?? 0
- : 0}{" "}
- Attributes
- </Button>
+ <ButtonGroup size="sm" isAttached variant="outline">
+ <Button
+ onClick={() => {
+ navigate(`/app/users/attributes/list/${row.original.id}`);
+ }}
+ >
+ {Array.isArray(row.original.userAttribute)
+ ? row.original.userAttribute?.length ?? 0
+ : 0}{" "}
+ Attributes
+ </Button>
+ <IconButton
+ aria-label="Add to friends"
+ icon={<BsPlus />}
+ onClick={() => {
+ navigate(`/app/users/attributes/list/${row.original.id}/new`);
+ }}
+ />
+ </ButtonGroup>
),
},
{
@@ -70,14 +81,13 @@ const AttributeCategoriesTable = memo(
cell: (item) => {
const isPublic = item.getValue<boolean>().toString() === "true";
return (
- <Tag
- size="md"
- borderRadius="full"
- variant={isPublic ? "solid" : "outline"}
+ <Badge
+ size="sm"
+ variant={isPublic ? undefined : "outline"}
colorScheme={isPublic ? "green" : "gray "}
>
- <TagLabel>{isPublic ? "Public" : "Private"}</TagLabel>
- </Tag>
+ {isPublic ? "Public" : "Private"}
+ </Badge>
);
},
},
diff --git a/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoryDetail/AttributeCategoryDetail.tsx b/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoryDetail/AttributeCategoryDetail.tsx
index 1c0212cb40..cf9e3c361b 100644
--- a/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoryDetail/AttributeCategoryDetail.tsx
+++ b/apps/carbon/app/interfaces/Users/Attributes/AttributeCategoryDetail/AttributeCategoryDetail.tsx
@@ -153,7 +153,7 @@ const AttributeCategoryDetail = ({
// @ts-ignore
attributeMap[sortId]?.attributeDataType
)}
- variant="ghost`"
+ variant="ghost"
>
{
// @ts-ignore
@@ -168,10 +168,12 @@ const AttributeCategoryDetail = ({
to={sortId.toString()}
aria-label="Edit"
icon={<BsPencilSquare />}
+ variant="ghost"
/>
<IconButton
aria-label="Delete"
icon={<IoMdTrash />}
+ variant="ghost"
onClick={() =>
// @ts-ignore
onDelete(attributeMap[sortId])
diff --git a/apps/carbon/app/interfaces/Users/BulkEditPermissions/BulkEditPermissionsForm.tsx b/apps/carbon/app/interfaces/Users/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx
similarity index 97%
rename from apps/carbon/app/interfaces/Users/BulkEditPermissions/BulkEditPermissionsForm.tsx
rename to apps/carbon/app/interfaces/Users/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx
index 8df7455d5c..6f3a9ed581 100644
--- a/apps/carbon/app/interfaces/Users/BulkEditPermissions/BulkEditPermissionsForm.tsx
+++ b/apps/carbon/app/interfaces/Users/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx
@@ -17,8 +17,8 @@ import { useEffect, useState } from "react";
import { ValidatedForm } from "remix-validated-form";
import { Hidden, Radios, Submit, Users } from "~/components/Form";
import { bulkPermissionsValidator } from "~/services/users";
-import PermissionCheckboxes from "../components/Permission";
-import type { Permission } from "../types";
+import PermissionCheckboxes from "../../components/Permission";
+import type { Permission } from "../../types";
type BulkEditPermissionsProps = {
userIds: string[];
diff --git a/apps/carbon/app/interfaces/Users/BulkEditPermissions/index.ts b/apps/carbon/app/interfaces/Users/Employees/BulkEditPermissionsForm/index.ts
similarity index 62%
rename from apps/carbon/app/interfaces/Users/BulkEditPermissions/index.ts
rename to apps/carbon/app/interfaces/Users/Employees/BulkEditPermissionsForm/index.ts
index c65bb9107d..ca24516d50 100644
--- a/apps/carbon/app/interfaces/Users/BulkEditPermissions/index.ts
+++ b/apps/carbon/app/interfaces/Users/Employees/BulkEditPermissionsForm/index.ts
@@ -1,3 +1,3 @@
import BulkEditPermissionsForm from "./BulkEditPermissionsForm";
-export { BulkEditPermissionsForm };
+export default BulkEditPermissionsForm;
diff --git a/apps/carbon/app/interfaces/Users/Employees/DeactivateEmployeesModal/DeactivateEmployeesModal.tsx b/apps/carbon/app/interfaces/Users/Employees/DeactivateEmployeesModal/DeactivateEmployeesModal.tsx
new file mode 100644
index 0000000000..0d63b5c861
--- /dev/null
+++ b/apps/carbon/app/interfaces/Users/Employees/DeactivateEmployeesModal/DeactivateEmployeesModal.tsx
@@ -0,0 +1,80 @@
+import {
+ Button,
+ HStack,
+ Modal,
+ ModalBody,
+ ModalCloseButton,
+ ModalContent,
+ ModalFooter,
+ ModalHeader,
+ ModalOverlay,
+ Text,
+} from "@chakra-ui/react";
+import { ValidatedForm } from "remix-validated-form";
+import { UserSelect } from "~/components/Selectors";
+import { deactivateUsersValidator } from "~/services/users";
+
+type DeactivateEmployeesModalProps = {
+ userIds: string[];
+ isOpen: boolean;
+ onClose: () => void;
+};
+
+const DeactivateEmployeesModal = ({
+ userIds,
+ isOpen,
+ onClose,
+}: DeactivateEmployeesModalProps) => {
+ const isSingleUser = userIds.length === 1;
+
+ return (
+ <Modal isOpen={isOpen} onClose={onClose}>
+ <ModalOverlay />
+ <ModalContent>
+ <ModalHeader>
+ {isSingleUser ? "Deactivate Employee" : "Deactivate Employees"}
+ </ModalHeader>
+ <ModalCloseButton />
+ <ModalBody>
+ <Text mb={2}>
+ Are you sure you want to deactive
+ {isSingleUser ? " this user" : " these users"}?
+ </Text>
+ <UserSelect value={userIds} readOnly isMulti />
+ </ModalBody>
+ <ModalFooter>
+ <HStack spacing={2}>
+ <Button variant="ghost" onClick={onClose}>
+ Cancel
+ </Button>
+ <ValidatedForm
+ method="post"
+ action="/app/users/deactivate"
+ validator={deactivateUsersValidator}
+ onSubmit={onClose}
+ >
+ {userIds.map((id, index) => (
+ <input
+ key={id}
+ type="hidden"
+ name={`users[${index}]`}
+ value={id}
+ />
+ ))}
+ <input
+ type="hidden"
+ name="redirectTo"
+ value="/app/users/employees"
+ />
+ <Button colorScheme="red" type="submit">
+ Deactivate
+ </Button>
+ </ValidatedForm>
+ </HStack>
+ </ModalFooter>
+ </ModalContent>
+ </Modal>
+ );
+};
+
+export default DeactivateEmployeesModal;
diff --git a/apps/carbon/app/interfaces/Users/Employees/DeactivateEmployeesModal/index.ts b/apps/carbon/app/interfaces/Users/Employees/DeactivateEmployeesModal/index.ts
new file mode 100644
index 0000000000..e69991d9fa
--- /dev/null
+++ b/apps/carbon/app/interfaces/Users/Employees/DeactivateEmployeesModal/index.ts
@@ -0,0 +1,2 @@
+import DeactivateEmployeesModal from "./DeactivateEmployeesModal";
+export default DeactivateEmployeesModal;
diff --git a/apps/carbon/app/interfaces/Users/Employees/EmployeesTable/EmployeesTable.tsx b/apps/carbon/app/interfaces/Users/Employees/EmployeesTable/EmployeesTable.tsx
index e0e5d0b99d..01af9062c8 100644
--- a/apps/carbon/app/interfaces/Users/Employees/EmployeesTable/EmployeesTable.tsx
+++ b/apps/carbon/app/interfaces/Users/Employees/EmployeesTable/EmployeesTable.tsx
@@ -1,6 +1,7 @@
import { ActionMenu } from "@carbon/react";
import {
Flex,
+ HStack,
MenuItem,
useDisclosure,
VisuallyHidden,
@@ -8,33 +9,40 @@ import {
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
-import { BsPencilSquare } from "react-icons/bs";
+import { BsEnvelope, BsPencilSquare, BsShieldLock } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Table } from "~/components";
+import { Avatar, Table } from "~/components";
import { usePermissions } from "~/hooks";
import type { Employee } from "~/interfaces/Users/types";
-import { BulkEditPermissionsForm } from "~/interfaces/Users/BulkEditPermissions";
-import { Avatar } from "~/components";
+import {
+ BulkEditPermissionsForm,
+ DeactivateEmployeesModal,
+ ResendInviteModal,
+} from "~/interfaces/Users/Employees";
+import { FaBan } from "react-icons/fa";
type EmployeesTableProps = {
data: Employee[];
count: number;
- withSelectableRows?: boolean;
+ isEditable?: boolean;
};
const defaultColumnVisibility = {
- Avatar: false,
user_firstName: false,
user_lastName: false,
};
const EmployeesTable = memo(
- ({ data, count, withSelectableRows = false }: EmployeesTableProps) => {
+ ({ data, count, isEditable = false }: EmployeesTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
- const bulkEditDrawer = useDisclosure();
+
const [selectedUserIds, setSelectedUserIds] = useState<string[]>([]);
+ const bulkEditDrawer = useDisclosure();
+ const deactivateEmployeeModal = useDisclosure();
+ const resendInviteModal = useDisclosure();
+
const rows = useMemo(
() =>
data.map((d) => {
@@ -56,20 +64,27 @@ const EmployeesTable = memo(
const columns = useMemo<ColumnDef<typeof rows[number]>[]>(() => {
return [
{
- header: "Avatar",
+ header: "User",
cell: ({ row }) => (
- <Avatar
- size="sm"
- // @ts-ignore
- path={row.original.user?.avatarUrl}
- />
+ <HStack spacing={2}>
+ <Avatar
+ size="sm"
+ // @ts-ignore
+ name={row.original.user?.fullName}
+ // @ts-ignore
+ path={row.original.user?.avatarUrl}
+ />
+
+ <span>
+ {
+ // @ts-ignore
+ `${row.original.user?.firstName} ${row.original.user?.lastName}`
+ }
+ </span>
+ </HStack>
),
},
- {
- accessorKey: "user.fullName",
- header: "Full Name",
- cell: (item) => item.getValue(),
- },
+
{
accessorKey: "user.firstName",
header: "First Name",
@@ -100,22 +115,36 @@ const EmployeesTable = memo(
<MenuItem
icon={<BsPencilSquare />}
onClick={() =>
- navigate(`/app/users/employees/${item.getValue()}`)
+ navigate(
+ `/app/users/employees/${item.getValue() as string}`
+ )
}
>
Edit Employee
</MenuItem>
<MenuItem
- icon={<IoMdTrash />}
- onClick={(e) => {
- e.stopPropagation();
- navigate(
- `/app/users/employeess/deactivate/${item.getValue()}`
- );
+ icon={<BsEnvelope />}
+ onClick={() => {
+ setSelectedUserIds([item.getValue() as string]);
+ resendInviteModal.onOpen();
}}
>
- Deactivate Employee
+ Send Account Invite
</MenuItem>
+ {
+ // @ts-ignore
+ item.row.original.user?.active === true && (
+ <MenuItem
+ icon={<IoMdTrash />}
+ onClick={(e) => {
+ setSelectedUserIds([item.getValue() as string]);
+ deactivateEmployeeModal.onOpen();
+ }}
+ >
+ Deactivate Employee
+ </MenuItem>
+ )
+ }
</ActionMenu>
)}
</Flex>
@@ -129,6 +158,7 @@ const EmployeesTable = memo(
return [
{
label: "Bulk Edit Permissions",
+ icon: <BsShieldLock />,
disabled: !permissions.can("update", "users"),
onClick: (selected: typeof rows) => {
setSelectedUserIds(
@@ -142,10 +172,50 @@ const EmployeesTable = memo(
bulkEditDrawer.onOpen();
},
},
+ {
+ label: "Send Account Invite",
+ icon: <BsEnvelope />,
+ disabled: !permissions.can("create", "users"),
+ onClick: (selected: typeof rows) => {
+ setSelectedUserIds(
+ selected.reduce<string[]>((acc, row) => {
+ if (row.user && !Array.isArray(row.user)) {
+ acc.push(row.user.id);
+ }
+ return acc;
+ }, [])
+ );
+ resendInviteModal.onOpen();
+ },
+ },
+ {
+ label: "Deactivate Users",
+ icon: <FaBan />,
+ disabled: !permissions.can("delete", "users"),
+ onClick: (selected: typeof rows) => {
+ setSelectedUserIds(
+ selected.reduce<string[]>((acc, row) => {
+ if (row.user && !Array.isArray(row.user)) {
+ acc.push(row.user.id);
+ }
+ return acc;
+ }, [])
+ );
+ deactivateEmployeeModal.onOpen();
+ },
+ },
];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ // const editableComponents = useMemo(
+ // () => ({
+ // "user.firstName": EditableName,
+ // "user.lastName": EditableName,
+ // }),
+ // []
+ // );
+
return (
<>
<Table<typeof rows[number]>
@@ -157,7 +227,7 @@ const EmployeesTable = memo(
withColumnOrdering
withFilters
withPagination
- withSelectableRows={withSelectableRows}
+ withSelectableRows={isEditable}
/>
{bulkEditDrawer.isOpen && (
<BulkEditPermissionsForm
@@ -166,11 +236,58 @@ const EmployeesTable = memo(
onClose={bulkEditDrawer.onClose}
/>
)}
+ {deactivateEmployeeModal.isOpen && (
+ <DeactivateEmployeesModal
+ userIds={selectedUserIds}
+ isOpen={deactivateEmployeeModal.isOpen}
+ onClose={deactivateEmployeeModal.onClose}
+ />
+ )}
+ {resendInviteModal.isOpen && (
+ <ResendInviteModal
+ userIds={selectedUserIds}
+ isOpen={resendInviteModal.isOpen}
+ onClose={resendInviteModal.onClose}
+ />
+ )}
</>
);
}
);
+// const EditableName = ({
+// value,
+// row,
+// accessorKey,
+// onUpdate,
+// }: EditableTableCellComponentProps<Employee>) => {
+// const { supabase } = useSupabase();
+// // @ts-ignore
+// const userId = row?.user?.id as string;
+// if (userId === undefined) {
+// throw new Error("Expected user id to be defined");
+// }
+
+// const updateName = async (name: string) => {
+// const [table, column] = accessorKey.split(".");
+// onUpdate(name);
+// await supabase
+// ?.from(table)
+// .update({ [column]: name })
+// .eq("id", userId);
+// };
+
+// const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
+// if (event.key === "Enter") {
+// updateName(event.currentTarget.value);
+// }
+// };
+
+// return (
+// <Input autoFocus defaultValue={value as string} onKeyDown={onKeyDown} />
+// );
+// };
+
EmployeesTable.displayName = "EmployeeTable";
export default EmployeesTable;
diff --git a/apps/carbon/app/interfaces/Users/Employees/EmployeesTableFilters/EmployeesTableFilters.tsx b/apps/carbon/app/interfaces/Users/Employees/EmployeesTableFilters/EmployeesTableFilters.tsx
index 9e20578944..237728d46f 100644
--- a/apps/carbon/app/interfaces/Users/Employees/EmployeesTableFilters/EmployeesTableFilters.tsx
+++ b/apps/carbon/app/interfaces/Users/Employees/EmployeesTableFilters/EmployeesTableFilters.tsx
@@ -43,7 +43,6 @@ const EmployeesTableFilters = ({ employeeTypes }: EmployeeTypeFiltersProps) => {
<Select
// @ts-ignore
size="sm"
- colorScheme="brand"
value={employeeTypeOptions.filter(
(type) => type.value === params.get("type")
)}
@@ -56,6 +55,30 @@ const EmployeesTableFilters = ({ employeeTypes }: EmployeeTypeFiltersProps) => {
minW={180}
placeholder="Employee Type"
/>
+ <Select
+ // @ts-ignore
+ size="sm"
+ value={
+ params.get("active") === "false"
+ ? { value: "false", label: "Inactive" }
+ : { value: "true", label: "Active" }
+ }
+ options={[
+ {
+ value: "true",
+ label: "Active",
+ },
+ {
+ value: "false",
+ label: "Inactive",
+ },
+ ]}
+ onChange={(selected) => {
+ setParams({ active: selected?.value });
+ }}
+ aria-label="Active"
+ minW={180}
+ />
</HStack>
<HStack spacing={2}>
{permissions.can("create", "users") && (
diff --git a/apps/carbon/app/interfaces/Users/Employees/ResendInviteModal/ResendInviteModal.tsx b/apps/carbon/app/interfaces/Users/Employees/ResendInviteModal/ResendInviteModal.tsx
new file mode 100644
index 0000000000..0b0d5d4bc9
--- /dev/null
+++ b/apps/carbon/app/interfaces/Users/Employees/ResendInviteModal/ResendInviteModal.tsx
@@ -0,0 +1,78 @@
+import {
+ Button,
+ HStack,
+ Modal,
+ ModalBody,
+ ModalCloseButton,
+ ModalContent,
+ ModalFooter,
+ ModalHeader,
+ ModalOverlay,
+ Text,
+} from "@chakra-ui/react";
+import { useFetcher } from "@remix-run/react";
+import { ValidatedForm } from "remix-validated-form";
+import { UserSelect } from "~/components/Selectors";
+import { resendInviteValidator } from "~/services/users";
+
+type ResendInviteModalProps = {
+ userIds: string[];
+ isOpen: boolean;
+ onClose: () => void;
+};
+
+const ResendInviteModal = ({
+ userIds,
+ isOpen,
+ onClose,
+}: ResendInviteModalProps) => {
+ const fetcher = useFetcher();
+ const isSingleUser = userIds.length === 1;
+
+ return (
+ <Modal isOpen={isOpen} onClose={onClose}>
+ <ModalOverlay />
+ <ModalContent>
+ <ModalHeader>
+ {isSingleUser ? "Resend Invite" : "Resend Invites"}
+ </ModalHeader>
+ <ModalCloseButton />
+ <ModalBody>
+ <Text mb={2}>
+ Are you sure you want to resend an invite to
+ {isSingleUser ? " this user" : " these users"}?
+ </Text>
+ <UserSelect value={userIds} readOnly isMulti />
+ </ModalBody>
+ <ModalFooter>
+ <HStack spacing={2}>
+ <Button variant="ghost" onClick={onClose}>
+ Cancel
+ </Button>
+ <ValidatedForm
+ method="post"
+ action="/app/users/resend-invite"
+ validator={resendInviteValidator}
+ onSubmit={onClose}
+ fetcher={fetcher}
+ >
+ {userIds.map((id, index) => (
+ <input
+ key={id}
+ type="hidden"
+ name={`users[${index}]`}
+ value={id}
+ />
+ ))}
+ <Button colorScheme="brand" type="submit">
+ Send
+ </Button>
+ </ValidatedForm>
+ </HStack>
+ </ModalFooter>
+ </ModalContent>
+ </Modal>
+ );
+};
+
+export default ResendInviteModal;
diff --git a/apps/carbon/app/interfaces/Users/Employees/ResendInviteModal/index.ts b/apps/carbon/app/interfaces/Users/Employees/ResendInviteModal/index.ts
new file mode 100644
index 0000000000..c05fc8fad8
--- /dev/null
+++ b/apps/carbon/app/interfaces/Users/Employees/ResendInviteModal/index.ts
@@ -0,0 +1,3 @@
+import ResendInviteModal from "./ResendInviteModal";
+
+export default ResendInviteModal;
diff --git a/apps/carbon/app/interfaces/Users/Employees/index.ts b/apps/carbon/app/interfaces/Users/Employees/index.ts
index 61450632b4..c5242a9bb8 100644
--- a/apps/carbon/app/interfaces/Users/Employees/index.ts
+++ b/apps/carbon/app/interfaces/Users/Employees/index.ts
@@ -1,11 +1,17 @@
import CreateEmployeeModal from "./CreateEmployeeModal";
+import BulkEditPermissionsForm from "./BulkEditPermissionsForm";
+import DeactivateEmployeesModal from "./DeactivateEmployeesModal";
import EmployeePermissionsForm from "./EmployeePermissionsForm";
import EmployeesTable from "./EmployeesTable";
import EmployeesTableFilters from "./EmployeesTableFilters";
+import ResendInviteModal from "./ResendInviteModal";
export {
CreateEmployeeModal,
+ BulkEditPermissionsForm,
+ DeactivateEmployeesModal,
EmployeePermissionsForm,
EmployeesTable,
EmployeesTableFilters,
+ ResendInviteModal,
};
diff --git a/apps/carbon/app/queue/deactivate-users.queue.server.ts b/apps/carbon/app/queue/deactivate-users.queue.server.ts
new file mode 100644
index 0000000000..9b711e4e9e
--- /dev/null
+++ b/apps/carbon/app/queue/deactivate-users.queue.server.ts
@@ -0,0 +1,16 @@
+import { Queue } from "~/lib/bullmq";
+import { getSupabaseAdmin } from "~/lib/supabase";
+import { deactivateUser } from "~/services/users";
+
+export type DeactivateUserQueueData = {
+ id: string;
+};
+
+const client = getSupabaseAdmin();
+
+export const deactivateUsersQueue = Queue<DeactivateUserQueueData>(
+ "deactivateUsers:v1",
+ async (job) => {
+ await deactivateUser(client, job.data.id);
+ }
+);
diff --git a/apps/carbon/app/queue/index.ts b/apps/carbon/app/queue/index.ts
index 4d9b797656..031ec05cb7 100644
--- a/apps/carbon/app/queue/index.ts
+++ b/apps/carbon/app/queue/index.ts
@@ -1,4 +1,9 @@
import { bulkPermissionsQueue } from "./bulk-permissions.queue.server";
+import { deactivateUsersQueue } from "./deactivate-users.queue.server";
+import { resendInvitesQueue } from "./resend-invites.queue.server";
+
+export { bulkPermissionsQueue, deactivateUsersQueue, resendInvitesQueue };
-export { bulkPermissionsQueue };
export type { BulkPermissionsQueueData } from "./bulk-permissions.queue.server";
+export type { DeactivateUserQueueData } from "./deactivate-users.queue.server";
+export type { ResendInvitesQueueData } from "./resend-invites.queue.server";
diff --git a/apps/carbon/app/queue/resend-invites.queue.server.ts b/apps/carbon/app/queue/resend-invites.queue.server.ts
new file mode 100644
index 0000000000..30a98f4ea4
--- /dev/null
+++ b/apps/carbon/app/queue/resend-invites.queue.server.ts
@@ -0,0 +1,16 @@
+import { Queue } from "~/lib/bullmq";
+import { getSupabaseAdmin } from "~/lib/supabase";
+import { resendInvite } from "~/services/users";
+
+export type ResendInvitesQueueData = {
+ id: string;
+};
+
+const client = getSupabaseAdmin();
+
+export const resendInvitesQueue = Queue<ResendInvitesQueueData>(
+ "resendInvites:v1",
+ async (job) => {
+ await resendInvite(client, job.data.id);
+ }
+);
diff --git a/apps/carbon/app/routes/_auth.forgot-password.tsx b/apps/carbon/app/routes/_auth.forgot-password.tsx
index 3aa0894675..a6871f1f1a 100644
--- a/apps/carbon/app/routes/_auth.forgot-password.tsx
+++ b/apps/carbon/app/routes/_auth.forgot-password.tsx
@@ -21,7 +21,7 @@ import { forgotPasswordValidator, sendMagicLink } from "~/services/auth";
import { getUserByEmail } from "~/services/users";
import { assertIsPost } from "~/utils/http";
import type { FormActionData, Result } from "~/types";
-import { error } from "~/utils/result";
+import { error, success } from "~/utils/result";
export const meta: MetaFunction = () => ({
title: "Carbon | Forgot Password",
@@ -44,8 +44,9 @@ export async function action({ request }: ActionArgs): FormActionData {
}
const { email } = validation.data;
+ const user = await getUserByEmail(email);
- if ((await getUserByEmail(email))?.data) {
+ if (user.data && user.data.active) {
const authSession = await sendMagicLink(email);
if (!authSession) {
@@ -53,9 +54,13 @@ export async function action({ request }: ActionArgs): FormActionData {
status: 500,
});
}
+ } else {
+ return json(error(null, "User has been deactivated"), {
+ status: 500,
+ });
}
- return json({ success: true });
+ return json(success("Magic link sent"));
}
export default function ForgotPasswordRoute() {
diff --git a/apps/carbon/app/routes/_auth.login.tsx b/apps/carbon/app/routes/_auth.login.tsx
index 3ed39ab320..8500dc3256 100644
--- a/apps/carbon/app/routes/_auth.login.tsx
+++ b/apps/carbon/app/routes/_auth.login.tsx
@@ -51,8 +51,10 @@ export async function action({ request }: ActionArgs): FormActionData {
const authSession = await signInWithEmail(email, password);
if (!authSession) {
+ // delay on incorrect password as minimal brute force protection
+ await new Promise((resolve) => setTimeout(resolve, 2000));
return json(error(authSession, "Invalid email/password"), {
- status: 400,
+ status: 500,
});
}
diff --git a/apps/carbon/app/routes/_auth.reset-password.tsx b/apps/carbon/app/routes/_auth.reset-password.tsx
index d65be5a715..f378848313 100644
--- a/apps/carbon/app/routes/_auth.reset-password.tsx
+++ b/apps/carbon/app/routes/_auth.reset-password.tsx
@@ -14,8 +14,8 @@ import { redirect } from "@remix-run/node";
import { useNavigate } from "@remix-run/react";
import { ValidatedForm, validationError } from "remix-validated-form";
import { Password, Submit } from "~/components/Form";
-import { getSupabaseAdmin } from "~/lib/supabase";
-import { resetPasswordValidator } from "~/services/auth/auth.form";
+import { resetPasswordValidator } from "~/services/auth";
+import { resetPassword } from "~/services/users";
import { requireAuthSession, flash } from "~/services/session";
import { error, success } from "~/utils/result";
import { assertIsPost } from "~/utils/http";
@@ -38,12 +38,7 @@ export async function action({ request }: ActionArgs) {
const { password } = validation.data;
const { userId } = await requireAuthSession(request, { verify: true });
- const updatePassword = await getSupabaseAdmin().auth.admin.updateUserById(
- userId,
- {
- password,
- }
- );
+ const updatePassword = await resetPassword(userId, password);
if (updatePassword.error) {
return json(
diff --git a/apps/carbon/app/routes/app.account.tsx b/apps/carbon/app/routes/app.account.tsx
index 6d788853fd..68276304a9 100644
--- a/apps/carbon/app/routes/app.account.tsx
+++ b/apps/carbon/app/routes/app.account.tsx
@@ -15,7 +15,7 @@ export default function AccountRoute() {
const borderColor = useColor("gray.200");
return (
- <Grid w="full" h="full" templateColumns="auto 1fr" overflow="auto">
+ <Grid w="full" h="full" templateColumns="auto 1fr">
<ContentSidebar>
<VStack spacing={2}>
<VStack
diff --git a/apps/carbon/app/routes/app.users.attributes.list.$categoryId.$attributeId.tsx b/apps/carbon/app/routes/app.users.attributes.list.$categoryId.$attributeId.tsx
index 518510a52a..711ba070e2 100644
--- a/apps/carbon/app/routes/app.users.attributes.list.$categoryId.$attributeId.tsx
+++ b/apps/carbon/app/routes/app.users.attributes.list.$categoryId.$attributeId.tsx
@@ -46,8 +46,6 @@ export default function EditAttributeRoute() {
};
}>("/app/users/attributes");
- console.log("attribute", attribute);
-
return (
<AttributeForm
initialValues={{
diff --git a/apps/carbon/app/routes/app.users.attributes.tsx b/apps/carbon/app/routes/app.users.attributes.tsx
index 02a5a3e735..ce92075a2a 100644
--- a/apps/carbon/app/routes/app.users.attributes.tsx
+++ b/apps/carbon/app/routes/app.users.attributes.tsx
@@ -1,3 +1,4 @@
+import { VStack } from "@chakra-ui/react";
import type { LoaderArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
@@ -37,13 +38,13 @@ export default function UserAttributesRoute() {
const { categories } = useLoaderData<typeof loader>();
return (
- <>
+ <VStack w="full" h="full" spacing={0}>
<AttributeCategoriesTableFilters />
<AttributeCategoriesTable
data={categories.data ?? []}
count={categories.count ?? 0}
/>
<Outlet />
- </>
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/app.users.deactivate.tsx b/apps/carbon/app/routes/app.users.deactivate.tsx
new file mode 100644
index 0000000000..225210945d
--- /dev/null
+++ b/apps/carbon/app/routes/app.users.deactivate.tsx
@@ -0,0 +1,58 @@
+import type { ActionArgs } from "@remix-run/node";
+import { redirect } from "@remix-run/node";
+import { validationError } from "remix-validated-form";
+import type { DeactivateUserQueueData } from "~/queue";
+import { deactivateUsersQueue } from "~/queue";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session";
+import { deactivateUser, deactivateUsersValidator } from "~/services/users";
+import { safeRedirect } from "~/utils/http";
+import { error, success } from "~/utils/result";
+
+export async function action({ request }: ActionArgs) {
+ const { client } = await requirePermissions(request, {
+ delete: "users",
+ });
+
+ const validation = await deactivateUsersValidator.validate(
+ await request.formData()
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { users, redirectTo } = validation.data;
+
+ if (users.length === 1) {
+ const [userId] = users;
+ const result = await deactivateUser(client, userId);
+
+ return redirect(safeRedirect(redirectTo), await flash(request, result));
+ } else {
+ const jobs = users.map<{ name: string; data: DeactivateUserQueueData }>(
+ (id) => ({
+ name: `deactivate user ${id}`,
+ data: {
+ id,
+ },
+ })
+ );
+
+ try {
+ await deactivateUsersQueue.addBulk(jobs);
+ return redirect(
+ safeRedirect(redirectTo),
+ await flash(
+ request,
+ success("Success. Please check back in a few moments.")
+ )
+ );
+ } catch (e) {
+ return redirect(
+ safeRedirect(redirectTo),
+ await flash(request, error(e, "Failed to deactivate users"))
+ );
+ }
+ }
+}
diff --git a/apps/carbon/app/routes/app.users.employee-types.tsx b/apps/carbon/app/routes/app.users.employee-types.tsx
index 3c773eb190..a2e918c535 100644
--- a/apps/carbon/app/routes/app.users.employee-types.tsx
+++ b/apps/carbon/app/routes/app.users.employee-types.tsx
@@ -1,3 +1,4 @@
+import { VStack } from "@chakra-ui/react";
import type { LoaderArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
@@ -26,10 +27,10 @@ export default function EmployeeTypesRoute() {
const { data, count } = useLoaderData<typeof loader>();
return (
- <>
+ <VStack w="full" h="full" spacing={0}>
<EmployeeTypesTableFilters />
<EmployeeTypesTable data={data ?? []} count={count ?? 0} />
<Outlet />
- </>
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/app.users.employees.tsx b/apps/carbon/app/routes/app.users.employees.tsx
index 29c3a03882..3f407b03bc 100644
--- a/apps/carbon/app/routes/app.users.employees.tsx
+++ b/apps/carbon/app/routes/app.users.employees.tsx
@@ -1,3 +1,4 @@
+import { VStack } from "@chakra-ui/react";
import type { LoaderArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
@@ -19,11 +20,13 @@ export async function loader({ request }: LoaderArgs) {
const searchParams = new URLSearchParams(url.search);
const name = searchParams.get("name");
const type = searchParams.get("type");
+ const active = searchParams.get("active") !== "false";
+
const { limit, offset, sorts, filters } =
getGenericQueryFilters(searchParams);
const [employees, employeeTypes] = await Promise.all([
- getEmployees(client, { name, type, limit, offset, sorts, filters }),
+ getEmployees(client, { name, type, active, limit, offset, sorts, filters }),
getEmployeeTypes(client),
]);
@@ -35,14 +38,14 @@ export default function UsersEmployeesRoute() {
const permissions = usePermissions();
return (
- <>
+ <VStack w="full" h="full" spacing={0}>
<EmployeesTableFilters employeeTypes={employeeTypes.data ?? []} />
<EmployeesTable
data={employees.data ?? []}
count={employees.count ?? 0}
- withSelectableRows={permissions.can("update", "users")}
+ isEditable={permissions.can("update", "users")}
/>
<Outlet />
- </>
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/app.users.groups.tsx b/apps/carbon/app/routes/app.users.groups.tsx
index 2b45afdc5e..68a66323dc 100644
--- a/apps/carbon/app/routes/app.users.groups.tsx
+++ b/apps/carbon/app/routes/app.users.groups.tsx
@@ -1,3 +1,4 @@
+import { VStack } from "@chakra-ui/react";
import type { LoaderArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
@@ -41,10 +42,10 @@ export default function GroupsRoute() {
const { groups, count } = useLoaderData<typeof loader>();
return (
- <>
+ <VStack w="full" h="full" spacing={0}>
<GroupsTableFilters />
<GroupsTable data={groups ?? []} count={count ?? 0} />
<Outlet />
- </>
+ </VStack>
);
}
diff --git a/apps/carbon/app/routes/app.users.index.tsx b/apps/carbon/app/routes/app.users.index.tsx
index c51530dae7..53202c0a83 100644
--- a/apps/carbon/app/routes/app.users.index.tsx
+++ b/apps/carbon/app/routes/app.users.index.tsx
@@ -1,5 +1,10 @@
+import type { LoaderArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
-export async function loader() {
- return redirect("/app/users/employees");
+export async function loader({ request }: LoaderArgs) {
+ const url = new URL(request.url);
+ if (url.pathname === "/app/users") {
+ return redirect("/app/users/employees");
+ }
+ return null;
}
diff --git a/apps/carbon/app/routes/app.users.resend-invite.tsx b/apps/carbon/app/routes/app.users.resend-invite.tsx
new file mode 100644
index 0000000000..f6558fe418
--- /dev/null
+++ b/apps/carbon/app/routes/app.users.resend-invite.tsx
@@ -0,0 +1,54 @@
+import type { ActionArgs } from "@remix-run/node";
+import { json } from "@remix-run/node";
+import { validationError } from "remix-validated-form";
+import type { ResendInvitesQueueData } from "~/queue";
+import { resendInvitesQueue } from "~/queue";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session";
+import { resendInvite, resendInviteValidator } from "~/services/users";
+import { error, success } from "~/utils/result";
+
+export async function action({ request }: ActionArgs) {
+ const { client } = await requirePermissions(request, {
+ delete: "users",
+ });
+
+ const validation = await resendInviteValidator.validate(
+ await request.formData()
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { users } = validation.data;
+
+ if (users.length === 1) {
+ const [userId] = users;
+ const result = await resendInvite(client, userId);
+
+ return json({}, await flash(request, result));
+ } else {
+ const jobs = users.map<{ name: string; data: ResendInvitesQueueData }>(
+ (id) => ({
+ name: `reinvite user ${id}`,
+ data: {
+ id,
+ },
+ })
+ );
+
+ try {
+ await resendInvitesQueue.addBulk(jobs);
+ return json(
+ {},
+ await flash(request, success("Successfully added invites to queue."))
+ );
+ } catch (e) {
+ return json(
+ {},
+ await flash(request, error(e, "Failed to reinvite users"))
+ );
+ }
+ }
+}
diff --git a/apps/carbon/app/services/users/users.form.ts b/apps/carbon/app/services/users/users.form.ts
index 151a6e05fb..f7f2a7ca81 100644
--- a/apps/carbon/app/services/users/users.form.ts
+++ b/apps/carbon/app/services/users/users.form.ts
@@ -60,6 +60,15 @@ export const createEmployeeValidator = withZod(
})
);
+export const deactivateUsersValidator = withZod(
+ z.object({
+ redirectTo: z.string(),
+ users: z
+ .array(z.string().min(36, { message: "Invalid user id" }))
+ .min(1, { message: "Group members are required" }),
+ })
+);
+
export const employeeTypeValidator = withZod(
z.object({
id: z.string(),
@@ -95,13 +104,6 @@ export const employeeValidator = withZod(
})
);
-export const userPermissionsValidator = z.object({
- view: z.boolean(),
- create: z.boolean(),
- update: z.boolean(),
- delete: z.boolean(),
-});
-
export const groupValidator = withZod(
z.object({
id: z.string(),
@@ -111,3 +113,18 @@ export const groupValidator = withZod(
.min(1, { message: "Group members are required" }),
})
);
+
+export const resendInviteValidator = withZod(
+ z.object({
+ users: z
+ .array(z.string().min(36, { message: "Invalid user id" }))
+ .min(1, { message: "Group members are required" }),
+ })
+);
+
+export const userPermissionsValidator = z.object({
+ view: z.boolean(),
+ create: z.boolean(),
+ update: z.boolean(),
+ delete: z.boolean(),
+});
diff --git a/apps/carbon/app/services/users/users.server.ts b/apps/carbon/app/services/users/users.server.ts
index d1798a4b2e..11173129eb 100644
--- a/apps/carbon/app/services/users/users.server.ts
+++ b/apps/carbon/app/services/users/users.server.ts
@@ -16,6 +16,7 @@ import type { Result } from "~/types";
import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { error, success } from "~/utils/result";
+import logger from "~/lib/logger";
export async function createEmployeeAccount(
client: SupabaseClient<Database>,
@@ -108,6 +109,27 @@ async function createUser(
return { data, error };
}
+export async function deactivateUser(
+ client: SupabaseClient<Database>,
+ userId: string
+): Promise<Result> {
+ const updateActiveStatus = await client
+ .from("user")
+ .update({ active: false })
+ .eq("id", userId);
+ if (updateActiveStatus.error) {
+ return error(updateActiveStatus.error, "Failed to deactivate user");
+ }
+ const randomPassword = Math.random().toString(36).slice(-8);
+ const updatePassword = await resetPassword(userId, randomPassword);
+
+ if (updatePassword.error) {
+ return error(updatePassword.error, "Failed to deactivate user");
+ }
+
+ return success("Sucessfully deactivated user");
+}
+
export async function deleteAttribute(
client: SupabaseClient<Database>,
attributeId: string
@@ -229,12 +251,13 @@ export async function getEmployees(
args: GenericQueryFilters & {
name: string | null;
type: string | null;
+ active: boolean | null;
}
) {
let query = client
.from("employee")
.select(
- "user!inner(id, fullName, firstName, lastName, email, avatarUrl), employeeType!inner(name)",
+ "user!inner(id, fullName, firstName, lastName, email, avatarUrl, active), employeeType!inner(name)",
{ count: "exact" }
);
@@ -246,6 +269,10 @@ export async function getEmployees(
query = query.eq("employeeTypeId", args.type);
}
+ if (args.active !== null) {
+ query = query.eq("user.active", args.active);
+ }
+
query = setGenericQueryFilters(query, args, "user(lastName)");
return query;
}
@@ -604,6 +631,29 @@ export function makePermissionsFromEmployeeType(
return result;
}
+export async function resendInvite(
+ client: SupabaseClient<Database>,
+ userId: string
+): Promise<Result> {
+ const user = await getUserById(client, userId);
+ if (user.error || !user.data) {
+ return error(user.error, "Failed to get user");
+ }
+
+ const invite = await sendInviteByEmail(user.data.email);
+ if (invite.error) {
+ return error(invite.error, "Failed to send invite");
+ }
+
+ return success("Succesfully sent invite");
+}
+
+export async function resetPassword(userId: string, password: string) {
+ return getSupabaseAdmin().auth.admin.updateUserById(userId, {
+ password,
+ });
+}
+
async function setUserClaims(userId: string, claims: Record<string, boolean>) {
return getSupabaseAdmin().auth.admin.updateUserById(userId, {
app_metadata: claims,
diff --git a/apps/carbon/package.json b/apps/carbon/package.json
index 5c5f91a6f6..1cad254f71 100644
--- a/apps/carbon/package.json
+++ b/apps/carbon/package.json
@@ -37,8 +37,9 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "4.6.0",
+ "react-virtual": "2.10.4",
"reactflow": "^11.3.3",
- "remix-flat-routes": "^0.5.4",
+ "remix-flat-routes": "^0.5.6",
"remix-validated-form": "^4.6.5",
"zod": "^3.20.2",
"zod-form-data": "1.2.4"
diff --git a/docs/.eslintrc.js b/docs/.eslintrc.js
deleted file mode 100644
index 1308cba140..0000000000
--- a/docs/.eslintrc.js
+++ /dev/null
@@ -1,4 +0,0 @@
-module.exports = {
- root: true,
- extends: ["carbon"],
-};
diff --git a/docs/next-env.d.ts b/docs/next-env.d.ts
deleted file mode 100644
index 4f11a03dc6..0000000000
--- a/docs/next-env.d.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-/// <reference types="next" />
-/// <reference types="next/image-types/global" />
-
-// NOTE: This file should not be edited
-// see https://nextjs.org/docs/basic-features/typescript for more information.
diff --git a/docs/next.config.js b/docs/next.config.js
deleted file mode 100644
index 4a2b0fd93f..0000000000
--- a/docs/next.config.js
+++ /dev/null
@@ -1,6 +0,0 @@
-const withNextra = require("nextra")({
- theme: "nextra-theme-docs",
- themeConfig: "./theme.config.js",
- // optional: add `unstable_staticImage: true` to enable Nextra's auto image import
-});
-module.exports = withNextra();
diff --git a/docs/package.json b/docs/package.json
deleted file mode 100644
index b3e0b9c9cd..0000000000
--- a/docs/package.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "name": "docs",
- "version": "0.0.0",
- "private": true,
- "scripts": {
- "build": "next build",
- "clean": "rm -rf .turbo rm -rf .next && rm -rf node_modules",
- "dev": "next dev -p 4111",
- "lint": "TIMING=1 next lint",
- "start": "next start "
- },
- "dependencies": {
- "next": "^12.3.0",
- "nextra": "^2.0.0-beta.32",
- "nextra-theme-docs": "^2.0.0-beta.32",
- "react": "^18.2.0",
- "react-dom": "^18.2.0"
- },
- "devDependencies": {
- "@carbon/tsconfig": "*",
- "@types/jest": "^26.0.22",
- "@types/node": "^18.11.0",
- "@types/react": "^18.0.21",
- "@types/react-dom": "^18.0.6",
- "eslint-config-carbon": "*",
- "typescript": "^4.8.3"
- }
-}
diff --git a/docs/pages/Permissions/_meta.json b/docs/pages/Permissions/_meta.json
deleted file mode 100644
index ab9da61a1d..0000000000
--- a/docs/pages/Permissions/_meta.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "overview": "Overview",
- "claims": "Claims",
- "permissions": "Permissions",
- "employee-types": "Employee Types",
- "groups": "Groups",
- "policies": "Policies"
-}
diff --git a/docs/pages/Permissions/claims.mdx b/docs/pages/Permissions/claims.mdx
deleted file mode 100644
index 01911c2b08..0000000000
--- a/docs/pages/Permissions/claims.mdx
+++ /dev/null
@@ -1,15 +0,0 @@
-## Claims
-
-Permissions and roles are stored in a single `JSONB` column called `raw_app_meta_data` in the `auth.users` table. The reason for storing everything in one row is for faster performance when performing RLS lookups.
-
-Each user has one role and many permissions is stored as key/value pairs, for example:
-
-```json
-{
- "role": "EMPLOYEE",
- "parts_view": true,
- "parts_create": false,
- "parts_update": false,
- "parts_delete": false
-}
-```
diff --git a/docs/pages/Permissions/employee-types.mdx b/docs/pages/Permissions/employee-types.mdx
deleted file mode 100644
index c3367d9d76..0000000000
--- a/docs/pages/Permissions/employee-types.mdx
+++ /dev/null
@@ -1 +0,0 @@
-# Employee Types
diff --git a/docs/pages/Permissions/groups.mdx b/docs/pages/Permissions/groups.mdx
deleted file mode 100644
index e97b3e912a..0000000000
--- a/docs/pages/Permissions/groups.mdx
+++ /dev/null
@@ -1 +0,0 @@
-# Groups
diff --git a/docs/pages/Permissions/overview.mdx b/docs/pages/Permissions/overview.mdx
deleted file mode 100644
index d59245c0d7..0000000000
--- a/docs/pages/Permissions/overview.mdx
+++ /dev/null
@@ -1,57 +0,0 @@
-import { Callout } from "nextra-theme-docs";
-
-# Overview
-
-The claims administrator can pull three levers to control what users can see and do. Because we use words that are used in different fashions in elsewhere, we'll define them here.
-
-1. **Permissions** - user-specific boolean values for each feature/action
-
-- `TABLE/FEATURE LEVEL`
-- The user can view documents
-- The user can delete parts
-
-2. **Groups** - a shorthand identifier for a set of users that can access to a specific resource
-
-- `ROW LEVEL`
-- The group can view the document
-- The group can view the post
-- The group can modify the proposal
-
-3. **Roles** - a single string from a predefined set used for row-level filters in the database
-
-- `ROW LEVEL`
-- The customer can view sales orders from his organization
-- The supplier can view purchase orders from his organization
-
-<Callout>
- Permissions grant broad access, while groups give more fine-grained control.
-</Callout>
-
-## Permissions
-
-Each _feature_ (parts, job, timecards) has four corresponding permissions:
-
-1. `*_view`
-2. `*_create`
-3. `*_update`
-4. `*_delete`
-
-So if there were 10 features, then each user would need 40 (4 ⨉ 10) permissions definitions. That's tedious work.
-
-## Employee Types
-
-To avoid checking 40 checkboxes for each user, we've created model we're calling an **Employee Type** which allow us to define a preset permissions-spec for a type of user (e.g. Engineer). The permissions can be modified at the individual level later, but it's a good starting point for user creation. Employee Types also serve as the users' first group.
-
-## Groups
-
-Users can belong to as many groups as you'd like. The basic gist is that a group is a set of users (or other groups). But ultimately, groups resolve to a set of people that can be used to filter database queries.
-
-## Roles
-
-There are currently only three roles:
-
-1. `EMPLOYEE`
-2. `CUSTOMER`
-3. `SUPPLIER`
-
-The `CUSTOMER` and `SUPPLIER` roles work to limit what a user can see through Row-Level Security (RLS).
diff --git a/docs/pages/Permissions/permissions.mdx b/docs/pages/Permissions/permissions.mdx
deleted file mode 100644
index b39acdb5ca..0000000000
--- a/docs/pages/Permissions/permissions.mdx
+++ /dev/null
@@ -1,51 +0,0 @@
-# Permissions
-
-Permissions are coarse-grain controls that give or restrict access to a broad resource. Permissions are stored as `JSONB` claims in the `auth.users` table. They are parsed and made ready for use by the application. On the client we use the `usePermissions` hook, and on the server we use the `requirePermissions` function. Both of these functions are relative to the authenticated user.
-
-import { Tabs, Tab } from "nextra-theme-docs";
-
-<Tabs items={["Client Side", "Server Side", "Database"]}>
- <Tab>
-```tsx
-function Component () {
- const permissions = usePermissions();
-
- return
- (permissions.can('create', 'parts'))
- ? <Button>Create Part</Button>
- : null
-}
-```
- </Tab>
- <Tab>
-```ts
-export async function loader({request}: LoaderArgs) {
- // a client is needed to access the database
- const { client } = await requirePermission(request, {
- view: "users"
- });
-
-return json(await getEmployees(client));
-}
-
-````
- </Tab>
- <Tab>
-```sql
-CREATE POLICY
-"Only users with the parts_view permission can SELECT from Parts"
-ON "Parts"
-FOR SELECT
-USING (coalesce(get_my_claim('parts_view'), false));
-````
-
- </Tab>
-</Tabs>
-
-import { Callout } from "nextra-theme-docs";
-
-<Callout>
- To bypass all policies and security, a server-side client can be created with
- the `getSupabaseAdmin()` method. This should be used with extreme caution and
- never on the client.
-</Callout>
diff --git a/docs/pages/Permissions/policies.mdx b/docs/pages/Permissions/policies.mdx
deleted file mode 100644
index 4be3163a37..0000000000
--- a/docs/pages/Permissions/policies.mdx
+++ /dev/null
@@ -1 +0,0 @@
-# Policies
diff --git a/docs/pages/_app.tsx b/docs/pages/_app.tsx
deleted file mode 100644
index ab58a80f6c..0000000000
--- a/docs/pages/_app.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import React from "react";
-import type { AppProps } from "next/app";
-import "nextra-theme-docs/style.css";
-
-export default function Nextra({ Component, pageProps }: AppProps) {
- return <Component {...pageProps} />;
-}
diff --git a/docs/pages/_meta.json b/docs/pages/_meta.json
deleted file mode 100644
index 77361f502a..0000000000
--- a/docs/pages/_meta.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "index": "Introduction",
- "get-started": "Get Started"
-}
diff --git a/docs/pages/conventions.mdx b/docs/pages/conventions.mdx
deleted file mode 100644
index d805b1078c..0000000000
--- a/docs/pages/conventions.mdx
+++ /dev/null
@@ -1,109 +0,0 @@
-# Conventions
-
-import { Callout } from "nextra-theme-docs";
-
-In order to maintain consistency across the code base, we have converged on a few conventions.
-
-<Callout>Conventions are meant to be challenged and improved!</Callout>
-
-## Components
-
-We use a few different file naming conventions across projects. The most common naming convention is for a component.
-
-<Callout>
- All of these are not always necessary, but provide a framwework for how we
- like to break up code.
-</Callout>
-
-- **`Component.tsx`** - the React component
-- **`Component.definitions.ts`** - the type definitions of props and state
-- **`Component.styles.tsx`** - the `@emotion/styled` components used by the component
-- **`Component.utils.ts`** - any utility functions used by the component
-- **`index.ts`** - the export of the component
-
-import { Tabs, Tab } from "nextra-theme-docs";
-
-<Tabs
- items={[
- "Counter.tsx",
- "Counter.definitions.ts",
- "Counter.styles.tsx",
- "Counter.utils.ts",
- "index.ts"
- ]}
->
- <Tab>
-
-```tsx
-import { CounterProps } from "./Counter.definitions";
-import { Count, DecrementButton, IncrementButton } from "./Counter.styles";
-
-const Counter = ({ value, onChange }: CounterProps) => {
- return (
- <Count>{value}</Count>
- <DecrementButton onClick={() => onChange(value-1)}>-1</DecrementButton>
- <IncrementButton onClick={() => onChange(value+1)}>+1</IncrementButton>
- );
-};
-```
-
- </Tab>
- <Tab>
-
-```ts
-export const CounterProps = {
- value: number,
- onChange: (value: number) => void
-};
-```
-
- </Tab>
- <Tab>
-
-```tsx
-import styled from "@emotion/styled";
-
-export const Count = styled.div`
- font-size: 24px;
- font-weight: 600;
- margin: 0 16px;
-`;
-
-export const Button = styled.button`
- background: #fff;
- border: 1px solid #000;
- border-radius: 4px;
- font-size: 16px;
- font-weight: 600;
- padding: 8px 16px;
-`;
-```
-
- </Tab>
- <Tab>
-
-```ts
-
-```
-
- </Tab>
- <Tab>
-```ts
-```
- </Tab>
- <Tab>
-
-```ts
-// not needed in this example
-```
-
- </Tab>
- <Tab>
-```ts
-import Counter from "./Counter";
-
-export default Counter;
-```
- </Tab>
-
-</Tabs>
diff --git a/docs/pages/get-started.mdx b/docs/pages/get-started.mdx
deleted file mode 100644
index bad55622f9..0000000000
--- a/docs/pages/get-started.mdx
+++ /dev/null
@@ -1 +0,0 @@
-# Getting Started
diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx
deleted file mode 100644
index 231094de41..0000000000
--- a/docs/pages/index.mdx
+++ /dev/null
@@ -1,3 +0,0 @@
-# Introduction
-
-Welcome to the carbon docs. Here you'll find best practices, documentation, and other resources to help you get started with frontend development at carbon.
diff --git a/docs/public/favicon.ico b/docs/public/favicon.ico
deleted file mode 100644
index b2cf8db488..0000000000
Binary files a/docs/public/favicon.ico and /dev/null differ
diff --git a/docs/public/logo.png b/docs/public/logo.png
deleted file mode 100644
index 7a60f73a18..0000000000
Binary files a/docs/public/logo.png and /dev/null differ
diff --git a/docs/theme.config.js b/docs/theme.config.js
deleted file mode 100644
index 7cd011c9d8..0000000000
--- a/docs/theme.config.js
+++ /dev/null
@@ -1,30 +0,0 @@
-// theme.config.js
-import Image from "next/image";
-
-export default {
- project: {
- link: "https://gitlab.com/barbinbrad/carbon", // GitHub link in the navbar
- },
- docsRepositoryBase:
- "https://gitlab.com/barbinbrad/carbon/blob/master/apps/docs", // base URL for the docs repository
- titleSuffix: " – Carbon",
- navigation: {
- next: true,
- prev: true,
- },
- darkMode: true,
- footer: {
- text: `Carbon ${new Date().getFullYear()} © All rights reserved.`,
- },
- editLink: {
- text: `View this page on Gitlab`,
- },
- logo: <Image src="/logo.png" width={40} height={40} />,
- head: (
- <>
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta name="description" content="Nextra: the next docs builder" />
- <meta name="og:title" content="Nextra: the next docs builder" />
- </>
- ),
-};
diff --git a/docs/tsconfig.json b/docs/tsconfig.json
deleted file mode 100644
index ac247675a0..0000000000
--- a/docs/tsconfig.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "exclude": ["node_modules"],
- "extends": "@carbon/tsconfig/nextjs.json",
- "compilerOptions": {
- "rootDir": "pages",
- "outDir": "dist"
- },
- "include": ["next-env.d.ts", "pages"]
-}
diff --git a/packages/carbon-database/prisma/migrations/20221202000000_employee/migration.sql b/packages/carbon-database/prisma/migrations/20221202000000_employee/migration.sql
index 70edca501f..133f69433e 100644
--- a/packages/carbon-database/prisma/migrations/20221202000000_employee/migration.sql
+++ b/packages/carbon-database/prisma/migrations/20221202000000_employee/migration.sql
@@ -12,10 +12,3 @@ ALTER TABLE "employee" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Only claims admin can view/modify employees" ON "employee" FOR ALL USING (is_claims_admin());
CREATE POLICY "Anyone that's authenticated can view employees" ON "employee" FOR SELECT USING (auth.role() = 'authenticated');
-CREATE TABLE "employeePersonalData" (
- "id" TEXT NOT NULL,
-
-
- CONSTRAINT "employeePersonalData_pkey" PRIMARY KEY ("id"),
- CONSTRAINT "employeePersonalData_id_fkey" FOREIGN KEY ("id") REFERENCES "employee"("id") ON DELETE CASCADE ON UPDATE NO ACTION
-)
\ No newline at end of file
diff --git a/packages/carbon-database/prisma/migrations/20221208000000_groups/migration.sql b/packages/carbon-database/prisma/migrations/20221208000000_groups/migration.sql
index 1bf3f9c2eb..a39d7f8b7c 100644
--- a/packages/carbon-database/prisma/migrations/20221208000000_groups/migration.sql
+++ b/packages/carbon-database/prisma/migrations/20221208000000_groups/migration.sql
@@ -138,7 +138,8 @@ CREATE VIEW "group_member" AS
FROM
"membership" gm
INNER JOIN "group" g ON g.id = gm."groupId"
- LEFT OUTER JOIN "user" u ON u.id = gm."memberUserId";
+ LEFT OUTER JOIN "user" u ON u.id = gm."memberUserId"
+ WHERE u.active = TRUE;
CREATE RECURSIVE VIEW groups_recursive
(
diff --git a/packages/carbon-database/prisma/migrations/20221227000000_attributes/migration.sql b/packages/carbon-database/prisma/migrations/20221227000000_attributes/migration.sql
index 6dbdc9e880..38486ef777 100644
--- a/packages/carbon-database/prisma/migrations/20221227000000_attributes/migration.sql
+++ b/packages/carbon-database/prisma/migrations/20221227000000_attributes/migration.sql
@@ -176,4 +176,48 @@ CREATE TABLE "userAttributeValue" (
UNIQUE ( "userAttributeId", "userId")
);
--- ALTER TABLE "userAttributeValue" ENABLE ROW LEVEL SECURITY;
\ No newline at end of file
+ALTER TABLE "userAttributeValue" ENABLE ROW LEVEL SECURITY;
+CREATE POLICY "Claims admin can view/modify user attribute values" ON "userAttributeValue" FOR ALL USING (is_claims_admin());
+CREATE POLICY "Users can insert attributes for themselves" ON "userAttributeValue" FOR UPDATE WITH CHECK (auth.uid() = "userId"::uuid);
+CREATE POLICY "Users can modify attributes for themselves" ON "userAttributeValue" FOR UPDATE WITH CHECK (auth.uid() = "userId"::uuid);
+CREATE POLICY "Users can view their own attribtues" ON "userAttributeValue" FOR SELECT USING (auth.uid() = "userId"::uuid);
+CREATE POLICY "Users can view other users attributes if the category is public" ON "userAttributeValue" FOR SELECT
+ USING (
+ auth.role() = 'authenticated' AND
+ "userAttributeValue"."userAttributeId" IN (
+ SELECT "id" FROM "userAttribute" WHERE "userAttributeCategoryId" IN (
+ SELECT "id" FROM "userAttributeCategory" WHERE "public" = true
+ )
+ )
+ );
+
+-- CREATE TABLE employee_personal_data (
+-- id SERIAL PRIMARY KEY,
+-- bank_account_number TEXT,
+-- bank_routing_number TEXT,
+-- drivers_license_number TEXT,
+-- social_security TEXT,
+-- user_id TEXT NOT NULL,
+-- key_id uuid NOT NULL DEFAULT '7da3ce7e-98f0-4c4f-9b63-b3f783eab919'::uuid,
+-- nonce BYTEA DEFAULT pgsodium.crypto_aead_det_noncegen(),
+
+-- CONSTRAINT "employee_personal_data_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE
+-- );
+
+-- SECURITY LABEL FOR pgsodium
+-- ON COLUMN employee_personal_data.bank_account
+-- IS 'ENCRYPT WITH KEY COLUMN key_id ASSOCIATED (user_id) NONCE nonce';
+
+-- SECURITY LABEL FOR pgsodium
+-- ON COLUMN employee_personal_data.bank_routing
+-- IS 'ENCRYPT WITH KEY COLUMN key_id ASSOCIATED (user_id) NONCE nonce';
+
+-- SECURITY LABEL FOR pgsodium
+-- ON COLUMN employee_personal_data.drivers_license
+-- IS 'ENCRYPT WITH KEY COLUMN key_id ASSOCIATED (user_id) NONCE nonce';
+
+-- SECURITY LABEL FOR pgsodium
+-- ON COLUMN employee_personal_data.social_security
+-- IS 'ENCRYPT WITH KEY COLUMN key_id ASSOCIATED (user_id) NONCE nonce';
+
+-- ALTER TABLE "employee_personal_data" ENABLE ROW LEVEL SECURITY;
\ No newline at end of file
diff --git a/packages/carbon-database/src/types.ts b/packages/carbon-database/src/types.ts
index ab74853295..8ef9edf3e4 100644
--- a/packages/carbon-database/src/types.ts
+++ b/packages/carbon-database/src/types.ts
@@ -87,17 +87,6 @@ export interface Database {
employeeTypeId?: string
}
}
- employeePersonalData: {
- Row: {
- id: string
- }
- Insert: {
- id: string
- }
- Update: {
- id?: string
- }
- }
employeeType: {
Row: {
id: string
diff --git a/packages/carbon-react/package.json b/packages/carbon-react/package.json
index 2374c46940..f697828389 100644
--- a/packages/carbon-react/package.json
+++ b/packages/carbon-react/package.json
@@ -31,8 +31,8 @@
"@react-stately/calendar": "^3.0.5",
"@react-stately/datepicker": "^3.2.1",
"@react-types/button": "^3.7.0",
- "@react-types/calendar": "^3.4.0",
- "@react-types/datepicker": "^3.4.0",
+ "@react-types/calendar": "^3.0.5",
+ "@react-types/datepicker": "^3.1.4",
"framer-motion": "^7.5.4",
"react-colorful": "^5.6.1",
"react-hook-form": "^7.37.0",
diff --git a/packages/carbon-react/src/Theme/focusRing.ts b/packages/carbon-react/src/Theme/focusRing.ts
new file mode 100644
index 0000000000..66dff7a63a
--- /dev/null
+++ b/packages/carbon-react/src/Theme/focusRing.ts
@@ -0,0 +1,26 @@
+export const focusRingOutlined = () => ({
+ field: {
+ _focus: {
+ borderColor: "var(--chakra-ui-focus-ring-color)",
+ boxShadow: "0 0 0 2px var(--chakra-ui-focus-ring-color)",
+ },
+ },
+});
+
+export const focusRingFilled = () => ({
+ field: {
+ _focus: {
+ borderColor: "var(--chakra-ui-focus-ring-color)",
+ boxShadow: "0 0 0 1px var(--chakra-ui-focus-ring-color)",
+ },
+ },
+});
+
+export const focusRingFlushed = () => ({
+ field: {
+ _focus: {
+ borderColor: "var(--chakra-ui-focus-ring-color)",
+ boxShadow: "0 1px 0 0 var(--chakra-ui-focus-ring-color)",
+ },
+ },
+});
diff --git a/packages/carbon-react/src/Theme/theme.ts b/packages/carbon-react/src/Theme/theme.ts
index d3e916bb58..4ab6f275af 100644
--- a/packages/carbon-react/src/Theme/theme.ts
+++ b/packages/carbon-react/src/Theme/theme.ts
@@ -1,11 +1,19 @@
+import {
+ focusRingFilled,
+ focusRingFlushed,
+ focusRingOutlined,
+} from "./focusRing";
import { colors } from "./palette";
-/* Examples:
- * Focus ring color: https://codesandbox.io/s/chakra-change-focus-ring-color-c2yis?file=/src/theme.ts
- */
-
export const theme = {
colors,
+ styles: {
+ global: {
+ ":host,:root": {
+ "--chakra-ui-focus-ring-color": "#002aff99",
+ },
+ },
+ },
components: {
Button: {
baseStyle: {},
@@ -45,6 +53,11 @@ export const theme = {
defaultProps: {
borderRadius: "md",
},
+ variants: {
+ outline: focusRingOutlined,
+ filled: focusRingFilled,
+ flushed: focusRingFlushed,
+ },
},
Radio: {
defaultProps: {
@@ -55,12 +68,27 @@ export const theme = {
defaultProps: {
borderRadius: "md",
},
+ variants: {
+ outline: focusRingOutlined,
+ filled: focusRingFilled,
+ flushed: focusRingFlushed,
+ },
},
Switch: {
defaultProps: {
colorScheme: "green",
},
},
+ TextArea: {
+ variants: {
+ outline: () => focusRingOutlined().field,
+ filled: () => focusRingFilled().field,
+ flushed: () => focusRingFlushed().field,
+ },
+ },
+ },
+ shadows: {
+ outline: "0 0 0 3px var(--chakra-ui-focus-ring-color)",
},
defaultProps: {
colorScheme: "gray",
diff --git a/packages/carbon-react/src/hooks/index.ts b/packages/carbon-react/src/hooks/index.ts
index 0415f44507..c48acca52a 100644
--- a/packages/carbon-react/src/hooks/index.ts
+++ b/packages/carbon-react/src/hooks/index.ts
@@ -3,5 +3,13 @@ import useDebounce from "./useDebounce";
import useEscape from "./useEscape";
import useHydrated from "./useHydrated";
import useInterval from "./useInterval";
+import useKeyboardShortcuts from "./useKeyboardShortcuts";
-export { useColor, useDebounce, useEscape, useHydrated, useInterval };
+export {
+ useColor,
+ useDebounce,
+ useEscape,
+ useHydrated,
+ useInterval,
+ useKeyboardShortcuts,
+};
diff --git a/packages/carbon-react/src/hooks/useKeyboardShortcuts.ts b/packages/carbon-react/src/hooks/useKeyboardShortcuts.ts
new file mode 100644
index 0000000000..96e5ebfde4
--- /dev/null
+++ b/packages/carbon-react/src/hooks/useKeyboardShortcuts.ts
@@ -0,0 +1,81 @@
+import { useEffect, useState } from "react";
+
+function includes(array: string[], element: string) {
+ return array.indexOf(element) >= 0;
+}
+
+/**
+ * Hook for listening on key events.
+ *
+ * @param {Object|Map} keyMap Key names mapped to event handlers. If a key name exists, its
+ * default behavior will be suppressed.
+ * @param {Array} whitelistNodes If target element is in the whitelist nodes array, will not
+ * trigger shortcut event
+ * @param {Array} whitelistClasses If target class is in the whitelist classes array, will not
+ * trigger shortcut event
+ */
+export default function useKeyboardShortcuts(
+ keyMap: { [id: string]: (event: KeyboardEvent) => void },
+ whitelistNodes: string[] = [],
+ whitelistClasses: string[] = []
+) {
+ const [lastKeydown, setLastKeydown] = useState<string | null>();
+
+ const handleKeydown = (event: any) => {
+ if (
+ !keyMap ||
+ includes(whitelistNodes, event.target.nodeName) ||
+ includes(whitelistClasses, event.target.className)
+ ) {
+ return;
+ }
+
+ let keyPressed = getKeyPresses(event);
+
+ if (keyMap[keyPressed]) {
+ /**
+ * combined keymap will trigger action on KeyDown event
+ * while single keymap will trigger action on KeyUp event
+ */
+ if (keyPressed.includes("+")) {
+ event.preventDefault();
+ keyMap[keyPressed](event);
+ setLastKeydown(null);
+ } else {
+ setLastKeydown(event.key);
+ event.preventDefault();
+ }
+ }
+ };
+
+ const handleKeyup = (event: any) => {
+ if (!keyMap) return;
+
+ if (keyMap[event.key] && lastKeydown === event.key) {
+ event.preventDefault();
+ keyMap[event.key](event);
+ setLastKeydown(null);
+ }
+ };
+
+ function getKeyPresses(event: KeyboardEvent) {
+ return event.metaKey && event.shiftKey
+ ? `Command+Shift+${event.key}`
+ : event.metaKey
+ ? `Command+${event.key}`
+ : event.shiftKey && event.key === "Enter"
+ ? `Shift+${event.key}`
+ : event.ctrlKey && event.key
+ ? `Control+${event.key}`
+ : event.key;
+ }
+
+ useEffect(() => {
+ window.addEventListener("keydown", handleKeydown);
+ window.addEventListener("keyup", handleKeyup);
+ return () => {
+ window.removeEventListener("keydown", handleKeydown);
+ window.removeEventListener("keyup", handleKeyup);
+ };
+ });
+}
diff --git a/packages/carbon-react/src/index.tsx b/packages/carbon-react/src/index.tsx
index 7bc84ea855..f1cf455f04 100644
--- a/packages/carbon-react/src/index.tsx
+++ b/packages/carbon-react/src/index.tsx
@@ -11,7 +11,14 @@ import { ActionMenu } from "./Overlay";
import { useNotification } from "./Message";
import ThemeProvider, { theme } from "./Theme";
import { ClientOnly } from "./SSR";
-import { useColor, useDebounce, useInterval, useHydrated } from "./hooks";
+import {
+ useColor,
+ useDebounce,
+ useEscape,
+ useInterval,
+ useHydrated,
+ useKeyboardShortcuts,
+} from "./hooks";
export type { OptionBase, OptionProps, GroupBase };
@@ -28,7 +35,9 @@ export {
theme,
useColor,
useDebounce,
- useInterval,
+ useEscape,
useHydrated,
+ useInterval,
+ useKeyboardShortcuts,
useNotification,
};
diff --git a/packages/carbon-utils/src/index.ts b/packages/carbon-utils/src/index.ts
index cbdd61a010..c66295f5f9 100644
--- a/packages/carbon-utils/src/index.ts
+++ b/packages/carbon-utils/src/index.ts
@@ -1 +1,2 @@
+export * from "./math";
export * from "./ssr";
diff --git a/packages/carbon-utils/src/math.ts b/packages/carbon-utils/src/math.ts
new file mode 100644
index 0000000000..8c1bb49dc6
--- /dev/null
+++ b/packages/carbon-utils/src/math.ts
@@ -0,0 +1,2 @@
+export const clip = (value: number, min: number, max: number) =>
+ Math.min(Math.max(value, min), max);
diff --git a/yarn.lock b/yarn.lock
index bbad51cee6..2b9ffd2f37 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2579,6 +2579,11 @@
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-4.6.1.tgz#ae31309cc0f600f2da22708697b3be4eb1e46f9e"
integrity sha512-3u2/XxvxB+Q7cMXHnKU0CpBiUK1QWqpgiBv28YDo1zOIJE3FCF8DI2vrp6vuwjGt5h0JGXDSvmSf4D4maVjJdw==
+"@reach/observe-rect@^1.1.0":
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/@reach/observe-rect/-/observe-rect-1.2.0.tgz#d7a6013b8aafcc64c778a0ccb83355a11204d3b2"
+ integrity sha512-Ba7HmkFgfQxZqqaeIWWkNK0rEhpxVQHIoVyW1YDSkGsGIXzcaW4deC8B0pZrNSSyLTdIk7y+5olKt5+g0GmFIQ==
+
"@react-aria/button@^3.6.4":
version "3.6.4"
resolved "https://registry.yarnpkg.com/@react-aria/button/-/button-3.6.4.tgz#51927c9d968d0c1f741ee2081ca7f2e244abbc12"
@@ -2608,7 +2613,7 @@
"@react-types/shared" "^3.16.0"
"@swc/helpers" "^0.4.14"
-"@react-aria/datepicker@^3.4.0":
+"@react-aria/datepicker@^3.2.1":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@react-aria/datepicker/-/datepicker-3.2.1.tgz#56a222c4b1c9c65b9b9371d3066611134f537ab7"
integrity sha512-NnW9VgX/YjxkgjcIaxmOhzpfiQmTQpCXjpPJ1+3nPhKzPKpcjtPxIYTDMkm/R+6i5FRukEGtjhg3QY9amLK6hQ==
@@ -2723,7 +2728,7 @@
"@react-types/shared" "^3.16.0"
"@swc/helpers" "^0.4.14"
-"@react-stately/datepicker@^3.2.1", "@react-stately/datepicker@^3.4.0":
+"@react-stately/datepicker@^3.2.1":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@react-stately/datepicker/-/datepicker-3.2.1.tgz#4c545981f73771bff76885e50014b4274fa4b554"
integrity sha512-nd6thX2Z+rOLDHduB3EgMKA0n5U83lrwn3IUfjRGrcE21zFaFmhTPsHyvol5jHy3eSyjWSN9kGpKFzOxES+uoA==
@@ -2769,7 +2774,7 @@
dependencies:
"@react-types/shared" "^3.16.0"
-"@react-types/calendar@^3.0.5", "@react-types/calendar@^3.4.0":
+"@react-types/calendar@^3.0.5":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@react-types/calendar/-/calendar-3.0.5.tgz#a91fca7d5a2bbbd554748471f9920600cb364d18"
integrity sha512-Kx00132hFEVvqay/Ub7q2oZEA1AzksirAuCsjakamn4LAXvitlo3PZxqBdEsyRc3nP5NR48KJj8yo276mXY8kQ==
@@ -2784,7 +2789,7 @@
dependencies:
"@react-types/shared" "^3.16.0"
-"@react-types/datepicker@^3.1.4", "@react-types/datepicker@^3.4.0":
+"@react-types/datepicker@^3.1.4":
version "3.1.4"
resolved "https://registry.yarnpkg.com/@react-types/datepicker/-/datepicker-3.1.4.tgz#46fd291d8acd40fdd304c4c0bf1a47e71eaa1801"
integrity sha512-NBCXBCe3YZqeA/JrVKy0IAvJ2XSnXaVpR9iAlUwKu7V8P81CtnXHsVCrd/0HSH8QZWsGdIV5E23z0TctvW8trA==
@@ -10362,6 +10367,13 @@ react-transition-group@^4.3.0:
loose-envify "^1.4.0"
prop-types "^15.6.2"
+ version "2.10.4"
+ resolved "https://registry.yarnpkg.com/react-virtual/-/react-virtual-2.10.4.tgz#08712f0acd79d7d6f7c4726f05651a13b24d8704"
+ integrity sha512-Ir6+oPQZTVHfa6+JL9M7cvMILstFZH/H3jqeYeKI4MSUX+rIruVwFC6nGVXw9wqAw8L0Kg2KvfXxI85OvYQdpQ==
+ dependencies:
+ "@reach/observe-rect" "^1.1.0"
+
react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
@@ -10608,10 +10620,10 @@ remeda@^1.2.0:
resolved "https://registry.yarnpkg.com/remeda/-/remeda-1.3.0.tgz#6dc642187e08ead2265e8c7f8517a16a69e325ce"
integrity sha512-DJkLBUzi0dEigDuyPtVe50aNzQq8EBQOintPaxvzwSNreXOGsRnvfGiK+cTsY+nUgGCBrcFxcvH8MIg2skfIZA==
-remix-flat-routes@^0.5.4:
- version "0.5.4"
- resolved "https://registry.yarnpkg.com/remix-flat-routes/-/remix-flat-routes-0.5.4.tgz#13614b75e1cce7f0394b04df0c932eebdf2ba4d7"
- integrity sha512-4Rw3CwWvP/jUx9IkEOEbiNbzxwc/nb4wE9mk1Q1fO3yz46CLUOOoqUCn1+0nwlKqOdyYb0iw3Q8FV7d6X2fAjw==
+remix-flat-routes@^0.5.6:
+ version "0.5.6"
+ resolved "https://registry.yarnpkg.com/remix-flat-routes/-/remix-flat-routes-0.5.6.tgz#58475b8ddba3d8a29cd7634f9e691a70efaf7a86"
+ integrity sha512-Y+cB9Fg5L21FGSpW703tMsoORgC02Qa4BS6JG/TOM0ccDSvPDpkl/XAbg86JtZ/9aytSa7nUORlcB1725y8kAQ==
dependencies:
minimatch "^5.1.0"