/// /** * Work Google Auth Wrapper * * Wraps the base google-auth pattern and adds the #googleAuthWork tag. * Use this when you want to explicitly mark an auth as "work". * * Can be used two ways: * 1. Pre-hoc: Create this directly, log in, and favorite * 2. Post-hoc: Created by google-auth-switcher after login */ import { computed, Default, ifElse, NAME, pattern, UI } from "commontools"; import GoogleAuth, { Auth, createPreviewUI, SelectedScopes, } from "./google-auth.tsx"; interface Input { selectedScopes: Default; auth: Default< Auth, { token: ""; tokenType: ""; scope: []; expiresIn: 0; expiresAt: 0; refreshToken: ""; user: { email: ""; name: ""; picture: "" }; } >; } /** Work Google account. #googleAuth #googleAuthWork */ interface Output { auth: Auth; accountType: "work"; /** Minimal preview for picker display with WORK badge */ previewUI: unknown; } export default pattern(({ auth, selectedScopes }) => { // Compose the base GoogleAuth pattern const baseAuth = GoogleAuth({ auth, selectedScopes }); // Enhanced preview with WORK badge using shared helper // Build scopes record manually (same pattern as google-auth.tsx to avoid type casting) const previewUI = computed(() => createPreviewUI( baseAuth.auth, { gmail: selectedScopes.gmail, gmailSend: selectedScopes.gmailSend, gmailModify: selectedScopes.gmailModify, calendar: selectedScopes.calendar, calendarWrite: selectedScopes.calendarWrite, drive: selectedScopes.drive, docs: selectedScopes.docs, contacts: selectedScopes.contacts, }, { text: "WORK", color: "#dc2626" }, ) ); return { [NAME]: computed(() => `Google Auth (Work)${ baseAuth.auth?.user?.email ? ` - ${baseAuth.auth.user.email}` : "" }` ), [UI]: (
{/* Account type badge */}
WORK {computed(() => baseAuth.auth?.user?.email || "Not logged in")}
{/* Embed the base auth UI */} {baseAuth as any} {/* Prominent favorite CTA - only show when logged in */} {ifElse( computed(() => !!baseAuth.auth?.user?.email),

Favorite This Piece!

Click the star to save your work Google auth

Patterns can then find it via{" "} #googleAuthWork

, null, )}
), auth: baseAuth.auth, accountType: "work" as const, previewUI, }; });