Continue secret sharing

This commit is contained in:
Tuan Dang
2024-07-29 14:32:11 -07:00
parent 938a7b7e72
commit c041e44399
32 changed files with 795 additions and 547 deletions
@@ -2,24 +2,46 @@ import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { SecretSharingAccessType, TSharedSecret, TViewSharedSecretResponse } from "./types";
import { TSharedSecret, TViewSharedSecretResponse } from "./types";
export const useGetSharedSecrets = () => {
export const secretSharingKeys = {
allSharedSecrets: () => ["sharedSecrets"] as const,
specificSharedSecrets: ({ offset, limit }: { offset: number; limit: number }) =>
[...secretSharingKeys.allSharedSecrets(), { offset, limit }] as const
};
export const useGetSharedSecrets = ({
offset = 0,
limit = 25
}: {
offset: number;
limit: number;
}) => {
return useQuery({
queryKey: ["sharedSecrets"],
queryKey: secretSharingKeys.specificSharedSecrets({ offset, limit }),
queryFn: async () => {
const { data } = await apiRequest.get<TSharedSecret[]>("/api/v1/secret-sharing/");
const params = new URLSearchParams({
offset: String(offset),
limit: String(limit)
});
const { data } = await apiRequest.get<{ secrets: TSharedSecret[]; totalCount: number }>(
"/api/v1/secret-sharing/",
{
params
}
);
return data;
}
});
};
export const useGetActiveSharedSecretByIdAndHashedHex = (id: string, hashedHex: string) => {
export const useGetActiveSharedSecretById = (secretId: string) => {
return useQuery<TViewSharedSecretResponse, [string]>({
enabled: Boolean(secretId),
queryFn: async () => {
if(!id || !hashedHex) return Promise.resolve({ encryptedValue: "", iv: "", tag: "", accessType: SecretSharingAccessType.Organization, orgName: "" });
const { data } = await apiRequest.get<TViewSharedSecretResponse>(
`/api/v1/secret-sharing/public/${id}?hashedHex=${hashedHex}`
`/api/v1/secret-sharing/public/${secretId}`
);
return {
encryptedValue: data.encryptedValue,