frontend client for gemstone. decentralised workplace app

feat: query for individual invite

serenity 984f58fd 0c2be813

Changed files
+51
src
+21
src/queries/get-invite-from-pds.ts
···
+
import type { AtUri } from "@/lib/types/atproto";
+
import type { SystemsGmstnDevelopmentChannelInvite } from "@/lib/types/lexicon/systems.gmstn.development.channel.invite";
+
import { systemsGmstnDevelopmentChannelInviteRecordSchema } from "@/lib/types/lexicon/systems.gmstn.development.channel.invite";
+
import { getRecordFromFullAtUri } from "@/lib/utils/atproto";
+
import type { Result } from "@/lib/utils/result";
+
+
export const getInviteFromPds = async (
+
atUri: Required<AtUri>,
+
): Promise<Result<SystemsGmstnDevelopmentChannelInvite, unknown>> => {
+
const record = await getRecordFromFullAtUri(atUri);
+
if (!record.ok) return { ok: false, error: record.error };
+
+
const {
+
success,
+
error,
+
data: invite,
+
} = systemsGmstnDevelopmentChannelInviteRecordSchema.safeParse(record.data);
+
if (!success) return { ok: false, error };
+
+
return { ok: true, data: invite };
+
};
+30
src/queries/hooks/useInviteQuery.ts
···
+
import type { AtUri } from "@/lib/types/atproto";
+
import { getInviteFromPds } from "@/queries/get-invite-from-pds";
+
import { useQuery } from "@tanstack/react-query";
+
+
export const useInviteQuery = (atUri: Required<AtUri>) => {
+
const queryKey = ["invite", atUri.authority, atUri.rKey];
+
return {
+
queryKey,
+
useQuery: () =>
+
useQuery({
+
queryKey,
+
queryFn: async () => {
+
return await pdsInviteQueryFn(atUri);
+
},
+
}),
+
};
+
};
+
+
const pdsInviteQueryFn = async (atUri: Required<AtUri>) => {
+
const invites = await getInviteFromPds(atUri);
+
+
if (!invites.ok) {
+
console.error("pdsInviteQueryFn error.", invites.error);
+
throw new Error(
+
`Something went wrong while getting the user's invite record directly.}`,
+
);
+
}
+
+
return invites.data;
+
};