{"version":3,"file":"TeamPage.mjs","names":[],"sources":["../../../../src/web/features/team/TeamPage.tsx"],"sourcesContent":["import { currentLocale, DEFAULT_LOCALE, useT } from '@agimon-ai/po-core/web';\nimport { useNavigate } from '@tanstack/react-router';\nimport { useStore } from '@tanstack/react-store';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { TEAM_ROUTE, useDashboardRoute } from '../../lib/dashboardRoute';\nimport { type PoTeam, type PoTeamClient, teamStore } from '../../stores/teamStore';\nimport { type TeamSection, TeamView } from './TeamView';\n\nconst sectionOf = (value: string | undefined): TeamSection =>\n  value === 'members' || value === 'invitations' ? value : 'overview';\nconst hrefOf = (section: TeamSection): string => (section === 'overview' ? TEAM_ROUTE : `${TEAM_ROUTE}/${section}`);\nconst messageOf = (error: unknown): string => (error instanceof Error ? error.message : String(error));\n// English keeps the browser's own region; a chosen language formats in that language.\nconst expiresOf = (iso: string): string => {\n  const locale = currentLocale();\n  return new Date(iso).toLocaleDateString(locale === DEFAULT_LOCALE ? undefined : locale, {\n    day: 'numeric',\n    month: 'short',\n  });\n};\n\n/**\n * The Team pages over the host's Po Cloud Team client. Every change reads the team again, so what shows is what\n * Po Cloud now holds. Leaving or deleting the team reloads the app, whose host then asks for another team.\n */\nexport function TeamPage() {\n  const t = useT();\n  const client = useStore(teamStore, (state) => state.client);\n  const route = useDashboardRoute();\n  const navigate = useNavigate();\n  const section = sectionOf(route.section);\n  const [team, setTeam] = useState<PoTeam>();\n  const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');\n  const [error, setError] = useState<string>();\n  const [notice, setNotice] = useState<string>();\n  const [pending, setPending] = useState(false);\n\n  const load = useCallback(async () => {\n    if (!client) return;\n    setStatus('loading');\n    try {\n      setTeam(await client.read());\n      setError(undefined);\n      setStatus('ready');\n    } catch (failure) {\n      setError(messageOf(failure));\n      setStatus('error');\n    }\n  }, [client]);\n  useEffect(() => {\n    if (client) void load();\n    // A Po without a Po Cloud team has no Team pages.\n    else void navigate({ to: '/', replace: true });\n  }, [client, load, navigate]);\n\n  const act = async (run: (client: PoTeamClient, team: PoTeam) => Promise<void>, done: string, after?: () => void) => {\n    if (!client || !team || pending) return;\n    setPending(true);\n    setError(undefined);\n    setNotice(undefined);\n    try {\n      await run(client, team);\n      if (after) return after();\n      setNotice(done);\n      setTeam(await client.read());\n    } catch (failure) {\n      setError(messageOf(failure));\n    } finally {\n      setPending(false);\n    }\n  };\n  const restart = () => window.location.assign('/');\n\n  if (!client) return null;\n  return (\n    <TeamView\n      section={section}\n      href={hrefOf}\n      onSection={(next) => void navigate({ to: hrefOf(next) })}\n      name={team?.name ?? ''}\n      role={team?.role ?? 'member'}\n      people={team?.people ?? []}\n      invites={(team?.invites ?? []).map((invite) => ({ ...invite, expires: expiresOf(invite.expiresAt) }))}\n      status={status}\n      pending={pending}\n      {...(error ? { error } : {})}\n      {...(notice ? { notice } : {})}\n      onRetry={() => void load()}\n      onRename={(name) =>\n        void act(\n          (cloud, current) => cloud.rename(current, name),\n          t('webDashboard.team.renamed', 'The team is now called {name}.', { name }),\n        )\n      }\n      onLeave={() => void act((cloud, current) => cloud.leave(current), '', restart)}\n      onDelete={() => void act((cloud, current) => cloud.delete(current), '', restart)}\n      onRole={(person, role) =>\n        void act(\n          (cloud, current) => cloud.setRole(current, person.id, role),\n          role === 'admin'\n            ? t('webDashboard.team.nowAdmin', '{name} is now an admin.', { name: person.name })\n            : t('webDashboard.team.nowMember', '{name} is now a member.', { name: person.name }),\n        )\n      }\n      onRemove={(person) =>\n        void act(\n          (cloud, current) => cloud.remove(current, person.id),\n          t('webDashboard.team.removed', '{name} no longer has access to {team}.', {\n            name: person.name,\n            team: team?.name ?? t('webDashboard.team.theTeam', 'the team'),\n          }),\n        )\n      }\n      onInvite={(email, role) =>\n        void act(\n          (cloud, current) => cloud.invite(current, email, role),\n          t('webDashboard.team.invited', 'Invitation sent to {email}. It expires in 7 days.', { email }),\n        )\n      }\n      onCancelInvite={(invite) =>\n        void act(\n          (cloud) => cloud.cancelInvite(invite.id),\n          t('webDashboard.team.inviteCancelled', 'The invitation to {email} is cancelled.', { email: invite.email }),\n        )\n      }\n    />\n  );\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,aAAa,UACjB,UAAU,aAAa,UAAU,gBAAgB,QAAQ;AAC3D,MAAM,UAAU,YAAkC,YAAY,aAAa,aAAa,GAAG,WAAW,GAAG;AACzG,MAAM,aAAa,UAA4B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAEpG,MAAM,aAAa,QAAwB;CACzC,MAAM,SAAS,cAAc;CAC7B,OAAO,IAAI,KAAK,GAAG,CAAC,CAAC,mBAAmB,WAAW,iBAAiB,KAAA,IAAY,QAAQ;EACtF,KAAK;EACL,OAAO;CACT,CAAC;AACH;;;;;AAMA,SAAgB,WAAW;CACzB,MAAM,IAAI,KAAK;CACf,MAAM,SAAS,SAAS,YAAY,UAAU,MAAM,MAAM;CAC1D,MAAM,QAAQ,kBAAkB;CAChC,MAAM,WAAW,YAAY;CAC7B,MAAM,UAAU,UAAU,MAAM,OAAO;CACvC,MAAM,CAAC,MAAM,WAAW,SAAiB;CACzC,MAAM,CAAC,QAAQ,aAAa,SAAwC,SAAS;CAC7E,MAAM,CAAC,OAAO,YAAY,SAAiB;CAC3C,MAAM,CAAC,QAAQ,aAAa,SAAiB;CAC7C,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAE5C,MAAM,OAAO,YAAY,YAAY;EACnC,IAAI,CAAC,QAAQ;EACb,UAAU,SAAS;EACnB,IAAI;GACF,QAAQ,MAAM,OAAO,KAAK,CAAC;GAC3B,SAAS,KAAA,CAAS;GAClB,UAAU,OAAO;EACnB,SAAS,SAAS;GAChB,SAAS,UAAU,OAAO,CAAC;GAC3B,UAAU,OAAO;EACnB;CACF,GAAG,CAAC,MAAM,CAAC;CACX,gBAAgB;EACd,IAAI,QAAQ,KAAU;OAEjB,SAAc;GAAE,IAAI;GAAK,SAAS;EAAK,CAAC;CAC/C,GAAG;E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