import { Box, Text } from "ink"; import { Button, ButtonList } from "../ui/Button.js"; import { Input } from "../ui/Input.js"; import { Popup } from "../ui/Popup.js"; import { useFreeSize } from "../../hooks/size.js"; import { useState } from "react"; import type { UpdateUser } from "../../../db/types/User.js"; import { deleteUserById, updateUser, } from "../../../react/store/actions/users.js"; import { useDataUserById } from "../../../react/hooks/data/users.js"; import { useAction } from "../../../react/hooks/useAction.js"; export function UserPopup({ uid, onClose, }: { uid: string; onClose: () => void; }) { const { user, status } = useDataUserById(uid); const del = useAction(deleteUserById); const upd = useAction(updateUser); const [changes, setChanges] = useState(null); const { width } = useFreeSize(); return ( {user ? ( <> Name:{" "} {changes ? ( setChanges((e) => ({ ...e!, name: v }))} /> ) : ( <>{user.name} )} Uid:{" "} {user.uid} Email:{" "} {changes ? ( setChanges((e) => ({ ...e!, email: v }))} /> ) : ( <> {"email" in user ? ( <>{user.email} ) : ( N/A )} )} Flags:{" "} {(user.flags.admin ?? false) && admin} Created: {user.created_at} Updated: {user.updated_at} {changes ? ( upd(changes).then(() => setChanges(null)), }, { children: "Discard", onClick: () => setChanges(null), }, ]} /> ) : ( { setChanges({ uid }); }, }, { children: "Delete", onClick: () => del(uid).then(onClose), }, ]} /> )} ) : ( <> {status} )} ); }