Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

guestShareAvailability.ts

22 lines1.1 KB

1import { managedCapabilityDenial } from "@t3tools/client-runtime/contract-labels";
2import type { EnvironmentId } from "@t3tools/contracts";
3import { Atom } from "effect/reactivity";
4​
5import { environmentPresentations } from "~/state/presentation";
6import { serverEnvironment } from "~/state/server";
7​
8/**
9 * Whether this environment offers "Share with guest": the user may create links there, and its
10 * Guest links beta is on (Settings > Labs). The server refuses links while the beta is off.
11 * Guests arrive through T3 Connect, so a policy that turns Connect off hides sharing too.
12 */
13export const canShareWithGuestAtom = Atom.family((environmentId: EnvironmentId) =>
14 Atom.make((get) => {
15 const serverConfig = get(environmentPresentations.serverConfigsAtom).get(environmentId);
16 return (
17 get(serverEnvironment.createGuestShare.permissionAtom(environmentId)) &&
18 serverConfig?.settings.guestSharingEnabled === true &&
19 managedCapabilityDenial(serverConfig.managedPolicy, "connect") === undefined
20 );
21 }).pipe(Atom.withLabel(`guest-share:available:${environmentId}`)),
22);