Compare commits

...

3 Commits

10 changed files with 148 additions and 65 deletions

View File

@ -1,10 +1,10 @@
import { useState } from "react";
import { BaseRecord } from "@refinedev/core";
import { useTable } from "@refinedev/react-table";
import { import {
ColumnDef, ColumnDef,
flexRender, flexRender,
getCoreRowModel, } from "@tanstack/react-table";
useReactTable,
getPaginationRowModel,
} from "@tanstack/react-table"
import { import {
Table, Table,
@ -16,20 +16,23 @@ import {
} from "./ui/table" } from "./ui/table"
import { DataTablePagination } from "./table-pagination" import { DataTablePagination } from "./table-pagination"
interface DataTableProps<TData, TValue> { interface DataTableProps<TData extends BaseRecord = BaseRecord, TValue = unknown> {
columns: ColumnDef<TData, TValue>[] columns: ColumnDef<TData, TValue>[]
data: TData[]
} }
export function DataTable<TData, TValue>({ export function DataTable<TData extends BaseRecord, TValue>({
columns, columns
data,
}: DataTableProps<TData, TValue>) { }: DataTableProps<TData, TValue>) {
const table = useReactTable({ const [hoveredRowId, setHoveredRowId] = useState<string>("");
data,
const table = useTable({
columns, columns,
getCoreRowModel: getCoreRowModel(), meta: {
getPaginationRowModel: getPaginationRowModel(), hoveredRowId,
},
refineCoreProps: {
resource: "files"
}
}) })
return ( return (
@ -40,7 +43,7 @@ export function DataTable<TData, TValue>({
<TableRow key={headerGroup.id}> <TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => { {headerGroup.headers.map((header) => {
return ( return (
<TableHead key={header.id}> <TableHead key={header.id} style={{ width: header.getSize() }}>
{header.isPlaceholder {header.isPlaceholder
? null ? null
: flexRender( : flexRender(
@ -59,6 +62,10 @@ export function DataTable<TData, TValue>({
<TableRow <TableRow
key={row.id} key={row.id}
data-state={row.getIsSelected() && "selected"} data-state={row.getIsSelected() && "selected"}
onMouseEnter={() => {
console.log(hoveredRowId, row.id);
setHoveredRowId(row.id)
}}
> >
{row.getVisibleCells().map((cell) => ( {row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}> <TableCell key={cell.id}>

View File

@ -14,7 +14,7 @@ import { useUppy } from "./lib/uppy";
import type { UppyFile } from "@uppy/core"; import type { UppyFile } from "@uppy/core";
import { Progress } from "~/components/ui/progress"; import { Progress } from "~/components/ui/progress";
import { DialogClose } from "@radix-ui/react-dialog"; import { DialogClose } from "@radix-ui/react-dialog";
import { ChevronDownIcon, TrashIcon } from "@radix-ui/react-icons"; import { ChevronDownIcon, ExitIcon, TrashIcon } from "@radix-ui/react-icons";
import { import {
ClockIcon, ClockIcon,
DriveIcon, DriveIcon,
@ -25,12 +25,17 @@ import {
PageIcon, PageIcon,
ThemeIcon, ThemeIcon,
} from "./icons"; } from "./icons";
import { DropdownMenu, DropdownMenuTrigger } from "./ui/dropdown-menu"; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem } from "./ui/dropdown-menu";
import { Avatar } from "@radix-ui/react-avatar"; import { Avatar } from "@radix-ui/react-avatar";
import { cn } from "~/utils"; import { cn } from "~/utils";
import { useGetIdentity, useLogout } from "@refinedev/core";
import { Identity } from "~/data/auth-provider";
export const GeneralLayout = ({ children }: React.PropsWithChildren<{}>) => { export const GeneralLayout = ({ children }: React.PropsWithChildren<{}>) => {
const location = useLocation(); const location = useLocation();
const { data: identity } = useGetIdentity<Identity>();
const{ mutate: logout } = useLogout()
return ( return (
<div className="h-full flex flex-row"> <div className="h-full flex flex-row">
<header className="p-10 pr-0 flex flex-col w-[240px] h-full scroll-m-0 overflow-hidden"> <header className="p-10 pr-0 flex flex-col w-[240px] h-full scroll-m-0 overflow-hidden">
@ -95,10 +100,18 @@ export const GeneralLayout = ({ children }: React.PropsWithChildren<{}>) => {
<DropdownMenuTrigger> <DropdownMenuTrigger>
<Button className="border rounded-full h-auto p-2 gap-x-2 text-ring font-semibold"> <Button className="border rounded-full h-auto p-2 gap-x-2 text-ring font-semibold">
<Avatar className="bg-ring h-7 w-7 rounded-full" /> <Avatar className="bg-ring h-7 w-7 rounded-full" />
whirly10 {`${identity?.firstName} ${identity?.lastName}`}
<ChevronDownIcon /> <ChevronDownIcon />
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuGroup>
<DropdownMenuItem onClick={() => logout()}>
<ExitIcon className="mr-2" />
Log Out
</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
</div> </div>

View File

@ -67,7 +67,7 @@ const DropdownMenuContent = React.forwardRef<
ref={ref} ref={ref}
sideOffset={sideOffset} sideOffset={sideOffset}
className={cn( className={cn(
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-primary p-1 text-white shadow-md",
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className className
)} )}
@ -80,14 +80,17 @@ DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
const DropdownMenuItem = React.forwardRef< const DropdownMenuItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Item>, React.ElementRef<typeof DropdownMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & { React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean inset?: boolean,
variant?: string
} }
>(({ className, inset, ...props }, ref) => ( >(({ className, inset, variant, ...props }, ref) => (
<DropdownMenuPrimitive.Item <DropdownMenuPrimitive.Item
ref={ref} ref={ref}
className={cn( className={cn(
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", "relative flex cursor-default select-none items-center rounded-md px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
inset && "pl-8", inset && "pl-8",
!variant && "focus:bg-primary-2/50 focus:text-primary-2-foreground",
variant === "destructive" && "focus:bg-destructive/50 focus:text-white",
className className
)} )}
{...props} {...props}
@ -165,7 +168,7 @@ const DropdownMenuSeparator = React.forwardRef<
>(({ className, ...props }, ref) => ( >(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.Separator <DropdownMenuPrimitive.Separator
ref={ref} ref={ref}
className={cn("-mx-1 my-1 h-px bg-muted", className)} className={cn("-mx-1 my-1 h-px bg-primary-2/75", className)}
{...props} {...props}
/> />
)) ))

View File

@ -1,3 +1,6 @@
import { useGetIdentity } from "@refinedev/core"
import { Identity } from "~/data/auth-provider"
import { import {
CrownIcon, CrownIcon,
PersonIcon, PersonIcon,
@ -10,13 +13,14 @@ import { Avatar } from "./ui/avatar"
import { Button } from "./ui/button" import { Button } from "./ui/button"
export const UpgradeAccountBanner = () => { export const UpgradeAccountBanner = () => {
const { data: identity } = useGetIdentity<Identity>();
return ( return (
<div className="flex items-center justify-between p-8 border border-ring rounded-lg bg-secondary-1"> <div className="flex items-center justify-between p-8 border border-ring rounded-lg bg-secondary-1">
<div className="flex items-center gap-x-4"> <div className="flex items-center gap-x-4">
<Avatar className="border-2 border-ring h-20 w-20" /> <Avatar className="border-2 border-ring h-20 w-20" />
<div> <div>
<div className="flex items-center gap-x-2 font-bold"> <div className="flex items-center gap-x-2 font-bold">
wirtly {`${identity?.firstName} ${identity?.lastName}`}
<CrownIcon className="text-ring" /> <CrownIcon className="text-ring" />
</div> </div>
<div className="flex gap-x-5 mt-2"> <div className="flex gap-x-5 mt-2">

View File

@ -1,15 +1,10 @@
import type { BaseRecord, CreateManyParams, CreateManyResponse, CreateParams, CreateResponse, CustomParams, CustomResponse, DataProvider, DeleteManyParams, DeleteManyResponse, DeleteOneParams, DeleteOneResponse, GetListParams, GetListResponse, GetManyParams, GetManyResponse, GetOneParams, GetOneResponse, UpdateManyParams, UpdateManyResponse, UpdateParams, UpdateResponse } from "@refinedev/core"; import type { DataProvider } from "@refinedev/core";
export class PortalFilesProvider implements DataProvider { export const defaultProvider: DataProvider = {
getList: <TData extends BaseRecord = BaseRecord>(params: GetListParams) => Promise<GetListResponse<TData>>; getList: () => { throw Error("Not Implemented") },
getMany?: (<TData extends BaseRecord = BaseRecord>(params: GetManyParams) => Promise<GetManyResponse<TData>>) | undefined; getOne: () => { throw Error("Not Implemented") },
getOne: <TData extends BaseRecord = BaseRecord>(params: GetOneParams) => Promise<GetOneResponse<TData>>; update: () => { throw Error("Not Implemented") },
create: <TData extends BaseRecord = BaseRecord, TVariables = {}>(params: CreateParams<TVariables>) => Promise<CreateResponse<TData>>; create: () => { throw Error("Not Implemented") },
createMany?: (<TData extends BaseRecord = BaseRecord, TVariables = {}>(params: CreateManyParams<TVariables>) => Promise<CreateManyResponse<TData>>) | undefined; deleteOne: () => { throw Error("Not Implemented") },
update: <TData extends BaseRecord = BaseRecord, TVariables = {}>(params: UpdateParams<TVariables>) => Promise<UpdateResponse<TData>>; getApiUrl: () => "",
updateMany?: (<TData extends BaseRecord = BaseRecord, TVariables = {}>(params: UpdateManyParams<TVariables>) => Promise<UpdateManyResponse<TData>>) | undefined;
deleteOne: <TData extends BaseRecord = BaseRecord, TVariables = {}>(params: DeleteOneParams<TVariables>) => Promise<DeleteOneResponse<TData>>;
deleteMany?: (<TData extends BaseRecord = BaseRecord, TVariables = {}>(params: DeleteManyParams<TVariables>) => Promise<DeleteManyResponse<TData>>) | undefined;
getApiUrl: () => string;
custom?: (<TData extends BaseRecord = BaseRecord, TQuery = unknown, TPayload = unknown>(params: CustomParams<TQuery, TPayload>) => Promise<CustomResponse<...>>) | undefined;
} }

View File

@ -14,6 +14,7 @@ import '@fontsource-variable/manrope';
import {Refine} from "@refinedev/core"; import {Refine} from "@refinedev/core";
import {PortalAuthProvider} from "~/data/auth-provider.js"; import {PortalAuthProvider} from "~/data/auth-provider.js";
import routerProvider from "@refinedev/remix-router"; import routerProvider from "@refinedev/remix-router";
import { defaultProvider } from "./data/file-provider";
export const links: LinksFunction = () => [ export const links: LinksFunction = () => [
{ rel: "stylesheet", href: stylesheet }, { rel: "stylesheet", href: stylesheet },
@ -42,6 +43,11 @@ export default function App() {
<Refine <Refine
authProvider={PortalAuthProvider.create("https://alpha.pinner.xyz")} authProvider={PortalAuthProvider.create("https://alpha.pinner.xyz")}
routerProvider={routerProvider} routerProvider={routerProvider}
dataProvider={defaultProvider}
resources={[
{ name: 'files' },
{ name: 'users' }
]}
> >
<Outlet/> <Outlet/>
</Refine> </Refine>

View File

@ -1,5 +1,6 @@
import { getFormProps, useForm } from "@conform-to/react"; import { getFormProps, useForm } from "@conform-to/react";
import { getZodConstraint, parseWithZod } from "@conform-to/zod"; import { getZodConstraint, parseWithZod } from "@conform-to/zod";
import { BaseKey, useGetIdentity, useUpdate, useUpdatePassword } from "@refinedev/core";
import { useState } from "react"; import { useState } from "react";
import { z } from "zod"; import { z } from "zod";
import { Field } from "~/components/forms"; import { Field } from "~/components/forms";
@ -19,10 +20,7 @@ import { UsageCard } from "~/components/usage-card";
import QRImg from "~/images/QR.png"; import QRImg from "~/images/QR.png";
export default function MyAccount() { export default function MyAccount() {
const isLogged = true; const { data: identity } = useGetIdentity<{ email: string }>();
if (!isLogged) {
window.location.href = "/login";
}
const [openModal, setModal] = useState({ const [openModal, setModal] = useState({
changeEmail: false, changeEmail: false,
@ -53,7 +51,7 @@ export default function MyAccount() {
<ManagementCard> <ManagementCard>
<ManagementCardTitle>Email Address</ManagementCardTitle> <ManagementCardTitle>Email Address</ManagementCardTitle>
<ManagementCardContent className="text-ring font-semibold"> <ManagementCardContent className="text-ring font-semibold">
bsimpson@springfield.oh.gov.com {identity?.email}
</ManagementCardContent> </ManagementCardContent>
<ManagementCardFooter> <ManagementCardFooter>
<Button className="h-12 gap-x-2" onClick={() => setModal({ ...openModal, changeEmail: true })}> <Button className="h-12 gap-x-2" onClick={() => setModal({ ...openModal, changeEmail: true })}>
@ -154,7 +152,7 @@ export default function MyAccount() {
setOpen={(value: boolean) => setOpen={(value: boolean) =>
setModal({ ...openModal, changeEmail: value }) setModal({ ...openModal, changeEmail: value })
} }
currentValue="bsimpson@springfield.oh.gov.com" currentValue={identity?.email || ""}
/> />
<ChangePasswordForm <ChangePasswordForm
open={openModal.changePassword} open={openModal.changePassword}
@ -176,6 +174,16 @@ const ChangeEmailSchema = z.object({
email: z.string().email(), email: z.string().email(),
password: z.string(), password: z.string(),
retypePassword: z.string(), retypePassword: z.string(),
})
.superRefine((data, ctx) => {
if (data.password !== data.retypePassword) {
return ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["retypePassword"],
message: "Passwords do not match",
});
}
return true;
}); });
const ChangeEmailForm = ({ const ChangeEmailForm = ({
@ -187,6 +195,8 @@ const ChangeEmailForm = ({
setOpen: (value: boolean) => void; setOpen: (value: boolean) => void;
currentValue: string; currentValue: string;
}) => { }) => {
const{ data: identity } = useGetIdentity<{ id: BaseKey }>();
const { mutate: updateEmail } = useUpdate();
const [form, fields] = useForm({ const [form, fields] = useForm({
id: "login", id: "login",
constraint: getZodConstraint(ChangeEmailSchema), constraint: getZodConstraint(ChangeEmailSchema),
@ -194,6 +204,19 @@ const ChangeEmailForm = ({
return parseWithZod(formData, { schema: ChangeEmailSchema }); return parseWithZod(formData, { schema: ChangeEmailSchema });
}, },
shouldValidate: "onSubmit", shouldValidate: "onSubmit",
onSubmit(e) {
e.preventDefault();
const data = Object.fromEntries(new FormData(e.currentTarget).entries());
console.log(identity);
updateEmail({
resource: 'users',
id: identity?.id || "",
values: {
email: data.email.toString()
}
})
}
}); });
return ( return (
@ -236,6 +259,16 @@ const ChangePasswordSchema = z.object({
currentPassword: z.string().email(), currentPassword: z.string().email(),
newPassword: z.string(), newPassword: z.string(),
retypePassword: z.string(), retypePassword: z.string(),
})
.superRefine((data, ctx) => {
if (data.newPassword !== data.retypePassword) {
return ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["retypePassword"],
message: "Passwords do not match",
});
}
return true;
}); });
const ChangePasswordForm = ({ const ChangePasswordForm = ({
@ -245,6 +278,7 @@ const ChangePasswordForm = ({
open: boolean; open: boolean;
setOpen: (value: boolean) => void; setOpen: (value: boolean) => void;
}) => { }) => {
const { mutate: updatePassword } = useUpdatePassword<{ password: string }>();
const [form, fields] = useForm({ const [form, fields] = useForm({
id: "login", id: "login",
constraint: getZodConstraint(ChangeEmailSchema), constraint: getZodConstraint(ChangeEmailSchema),
@ -252,6 +286,16 @@ const ChangePasswordForm = ({
return parseWithZod(formData, { schema: ChangePasswordSchema }); return parseWithZod(formData, { schema: ChangePasswordSchema });
}, },
shouldValidate: "onSubmit", shouldValidate: "onSubmit",
onSubmit(e) {
e.preventDefault();
const data = Object.fromEntries(new FormData(e.currentTarget).entries());
updatePassword({
password: data.newPassword.toString()
});
},
}); });
return ( return (
@ -270,7 +314,7 @@ const ChangePasswordForm = ({
/> />
<Field <Field
inputProps={{ name: fields.newPassword.name, type: "password" }} inputProps={{ name: fields.newPassword.name, type: "password" }}
labelProps={{ children: "Password" }} labelProps={{ children: "New Password" }}
errors={fields.newPassword.errors} errors={fields.newPassword.errors}
/> />
<Field <Field

View File

@ -1,6 +1,8 @@
import type { ColumnDef } from "@tanstack/react-table"; import { DrawingPinIcon, TrashIcon } from "@radix-ui/react-icons";
import type { ColumnDef, RowData } from "@tanstack/react-table";
import { FileIcon, MoreIcon } from "~/components/icons"; import { FileIcon, MoreIcon } from "~/components/icons";
import { Checkbox } from "~/components/ui/checkbox"; import { Checkbox } from "~/components/ui/checkbox";
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "~/components/ui/dropdown-menu";
// This type is used to define the shape of our data. // This type is used to define the shape of our data.
// You can use a Zod schema here if you want. // You can use a Zod schema here if you want.
@ -11,9 +13,16 @@ export type File = {
createdOn: string; createdOn: string;
}; };
declare module '@tanstack/table-core' {
interface TableMeta<TData extends RowData> {
hoveredRowId: string,
}
}
export const columns: ColumnDef<File>[] = [ export const columns: ColumnDef<File>[] = [
{ {
id: "select", id: "select",
size: 20,
header: ({ table }) => ( header: ({ table }) => (
<Checkbox <Checkbox
@ -55,11 +64,31 @@ export const columns: ColumnDef<File>[] = [
}, },
{ {
accessorKey: "createdOn", accessorKey: "createdOn",
size: 200,
header: "Created On", header: "Created On",
cell: ({ row }) => ( cell: ({ row, table }) => (
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
{row.getValue("createdOn")} {row.getValue("createdOn")}
{row.getIsSelected() && <MoreIcon />} {(row.getIsSelected() || table.options.meta?.hoveredRowId === row.id) && (
<DropdownMenu>
<DropdownMenuTrigger>
<MoreIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuGroup>
<DropdownMenuItem>
<DrawingPinIcon className="mr-2" />
Ping CID
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive">
<TrashIcon className="mr-2" />
Delete
</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
)}
</div> </div>
) )
} }

View File

@ -7,11 +7,6 @@ import { Button } from "~/components/ui/button";
import { AddIcon } from "~/components/icons"; import { AddIcon } from "~/components/icons";
export default function FileManager() { export default function FileManager() {
const isLogged = true;
if (!isLogged) {
window.location.href = "/login";
}
return ( return (
<GeneralLayout> <GeneralLayout>
<h1 className="font-bold mb-4 text-lg">File Manager</h1> <h1 className="font-bold mb-4 text-lg">File Manager</h1>
@ -60,20 +55,6 @@ export default function FileManager() {
</div> </div>
<DataTable <DataTable
columns={columns} columns={columns}
data={[
{
name: "whirly-final-draft.psd",
cid: "0xB45165ED3CD437B",
size: "1.89 MB",
createdOn: "03/02/2024 at 13:29 PM",
},
{
name: "whirly-final-draft.psd",
cid: "0xB45165ED3CD437B",
size: "1.89 MB",
createdOn: "03/02/2024 at 13:29 PM",
},
]}
/> />
</GeneralLayout> </GeneralLayout>
); );

View File

@ -28,6 +28,7 @@
"@refinedev/core": "https://gitpkg.now.sh/LumeWeb/refine/packages/core?remix", "@refinedev/core": "https://gitpkg.now.sh/LumeWeb/refine/packages/core?remix",
"@refinedev/devtools-internal": "https://gitpkg.now.sh/LumeWeb/refine/packages/devtools-internal?remix", "@refinedev/devtools-internal": "https://gitpkg.now.sh/LumeWeb/refine/packages/devtools-internal?remix",
"@refinedev/devtools-shared": "https://gitpkg.now.sh/LumeWeb/refine/packages/devtools-shared?remix", "@refinedev/devtools-shared": "https://gitpkg.now.sh/LumeWeb/refine/packages/devtools-shared?remix",
"@refinedev/react-table": "https://gitpkg.now.sh/LumeWeb/refine/packages/react-table?remix",
"@refinedev/remix-router": "https://gitpkg.now.sh/LumeWeb/refine/packages/remix?remix", "@refinedev/remix-router": "https://gitpkg.now.sh/LumeWeb/refine/packages/remix?remix",
"@remix-run/node": "^2.8.0", "@remix-run/node": "^2.8.0",
"@remix-run/react": "^2.8.0", "@remix-run/react": "^2.8.0",