Credentials UI (#1828)

This commit is contained in:
Shuchang Zheng
2025-02-24 11:54:18 -08:00
committed by GitHub
parent 39ab9c0603
commit c5a2438e7f
13 changed files with 337 additions and 27 deletions

View File

@@ -0,0 +1,66 @@
import { getClient } from "@/api/AxiosClient";
import { CredentialApiResponse } from "@/api/types";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Skeleton } from "@/components/ui/skeleton";
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { useQuery } from "@tanstack/react-query";
type Props = {
value: string;
onChange: (value: string) => void;
};
function CredentialSelector({ value, onChange }: Props) {
const credentialGetter = useCredentialGetter();
const { data: credentials, isFetching } = useQuery<
Array<CredentialApiResponse>
>({
queryKey: ["credentials"],
queryFn: async () => {
const client = await getClient(credentialGetter);
return await client.get("/credentials").then((res) => res.data);
},
});
if (isFetching) {
return <Skeleton className="h-10 w-full" />;
}
if (!credentials) {
return null;
}
return (
<Select value={value} onValueChange={onChange}>
<SelectTrigger>
<SelectValue placeholder="Select a credential" />
</SelectTrigger>
<SelectContent>
{credentials.map((credential) => (
<SelectItem
key={credential.credential_id}
value={credential.credential_id}
>
<div className="space-y-2">
<p className="text-sm font-medium">{credential.name}</p>
<p className="text-xs text-slate-400">
{credential.credential_type === "password"
? "Password"
: "Credit Card"}
</p>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
);
}
export { CredentialSelector };