@open-mercato/ui 0.6.5-develop.4882.1.901c3aa813 → 0.6.5-develop.4964.1.ae0edca575
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/portal/hooks/useTenantContext.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\nimport { useEffect, useState } from 'react'\nimport { apiCall } from '../../backend/utils/apiCall'\n\ntype OrgContext = {\n tenantId: string | undefined\n organizationId: string | undefined\n organizationName: string | undefined\n loading: boolean\n error: string | null\n}\n\n/**\n * Client-side hook for resolving organization/tenant context by slug.\n *\n * Used in portal pages before login/signup to resolve the tenant and organization\n * from the URL slug via `/api/directory/organizations/lookup`.\n *\n * @param orgSlug - Organization slug from the URL\n *\n * @example\n * ```tsx\n * import { useTenantContext } from '@open-mercato/ui/portal/hooks/useTenantContext'\n *\n * function LoginPage({ orgSlug }: { orgSlug: string }) {\n * const { tenantId, organizationId, organizationName, loading, error } = useTenantContext(orgSlug)\n * if (loading) return <LoadingMessage />\n * if (error) return <ErrorMessage error={error} />\n * // ...\n * }\n * ```\n */\nexport function useTenantContext(orgSlug: string): OrgContext {\n const [state, setState] = useState<OrgContext>({\n tenantId: undefined,\n organizationId: undefined,\n organizationName: undefined,\n loading: true,\n error: null,\n })\n\n useEffect(() => {\n let cancelled = false\n\n async function lookup() {\n if (!orgSlug) {\n setState((prev) => ({ ...prev, loading: false, error: 'No organization slug provided.' }))\n return\n }\n\n try {\n const { ok, result: data } = await apiCall<{ ok: boolean; organization: { id: string;
|
|
5
|
-
"mappings": ";AACA,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport { useEffect, useState } from 'react'\nimport { apiCall } from '../../backend/utils/apiCall'\n\ntype OrgContext = {\n /**\n * @deprecated The public org lookup no longer returns a tenant id; portal\n * flows send `organizationId` and the server resolves the tenant. Always\n * `undefined` \u2014 kept for backward compatibility with existing consumers.\n */\n tenantId: string | undefined\n organizationId: string | undefined\n organizationName: string | undefined\n loading: boolean\n error: string | null\n}\n\n/**\n * Client-side hook for resolving organization/tenant context by slug.\n *\n * Used in portal pages before login/signup to resolve the tenant and organization\n * from the URL slug via `/api/directory/organizations/lookup`.\n *\n * @param orgSlug - Organization slug from the URL\n *\n * @example\n * ```tsx\n * import { useTenantContext } from '@open-mercato/ui/portal/hooks/useTenantContext'\n *\n * function LoginPage({ orgSlug }: { orgSlug: string }) {\n * const { tenantId, organizationId, organizationName, loading, error } = useTenantContext(orgSlug)\n * if (loading) return <LoadingMessage />\n * if (error) return <ErrorMessage error={error} />\n * // ...\n * }\n * ```\n */\nexport function useTenantContext(orgSlug: string): OrgContext {\n const [state, setState] = useState<OrgContext>({\n tenantId: undefined,\n organizationId: undefined,\n organizationName: undefined,\n loading: true,\n error: null,\n })\n\n useEffect(() => {\n let cancelled = false\n\n async function lookup() {\n if (!orgSlug) {\n setState((prev) => ({ ...prev, loading: false, error: 'No organization slug provided.' }))\n return\n }\n\n try {\n const { ok, result: data } = await apiCall<{ ok: boolean; organization: { id: string; name: string }; error?: string }>(`/api/directory/organizations/lookup?slug=${encodeURIComponent(orgSlug)}`)\n if (cancelled) return\n\n if (!ok || !data?.ok || !data.organization) {\n setState((prev) => ({\n ...prev,\n loading: false,\n error: data?.error || 'Organization not found.',\n }))\n return\n }\n\n setState({\n tenantId: undefined,\n organizationId: data.organization.id,\n organizationName: data.organization.name,\n loading: false,\n error: null,\n })\n } catch {\n if (!cancelled) {\n setState((prev) => ({ ...prev, loading: false, error: 'Failed to load organization.' }))\n }\n }\n }\n\n lookup()\n return () => { cancelled = true }\n }, [orgSlug])\n\n return state\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AAmCjB,SAAS,iBAAiB,SAA6B;AAC5D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAqB;AAAA,IAC7C,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAED,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,mBAAe,SAAS;AACtB,UAAI,CAAC,SAAS;AACZ,iBAAS,CAAC,UAAU,EAAE,GAAG,MAAM,SAAS,OAAO,OAAO,iCAAiC,EAAE;AACzF;AAAA,MACF;AAEA,UAAI;AACF,cAAM,EAAE,IAAI,QAAQ,KAAK,IAAI,MAAM,QAAqF,4CAA4C,mBAAmB,OAAO,CAAC,EAAE;AACjM,YAAI,UAAW;AAEf,YAAI,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,cAAc;AAC1C,mBAAS,CAAC,UAAU;AAAA,YAClB,GAAG;AAAA,YACH,SAAS;AAAA,YACT,OAAO,MAAM,SAAS;AAAA,UACxB,EAAE;AACF;AAAA,QACF;AAEA,iBAAS;AAAA,UACP,UAAU;AAAA,UACV,gBAAgB,KAAK,aAAa;AAAA,UAClC,kBAAkB,KAAK,aAAa;AAAA,UACpC,SAAS;AAAA,UACT,OAAO;AAAA,QACT,CAAC;AAAA,MACH,QAAQ;AACN,YAAI,CAAC,WAAW;AACd,mBAAS,CAAC,UAAU,EAAE,GAAG,MAAM,SAAS,OAAO,OAAO,+BAA+B,EAAE;AAAA,QACzF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AACP,WAAO,MAAM;AAAE,kBAAY;AAAA,IAAK;AAAA,EAClC,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/ui",
|
|
3
|
-
"version": "0.6.5-develop.
|
|
3
|
+
"version": "0.6.5-develop.4964.1.ae0edca575",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -149,13 +149,13 @@
|
|
|
149
149
|
"remark-gfm": "^4.0.1"
|
|
150
150
|
},
|
|
151
151
|
"peerDependencies": {
|
|
152
|
-
"@open-mercato/shared": "0.6.5-develop.
|
|
152
|
+
"@open-mercato/shared": "0.6.5-develop.4964.1.ae0edca575",
|
|
153
153
|
"react": ">=18.0.0",
|
|
154
154
|
"react-dom": ">=18.0.0",
|
|
155
155
|
"react-is": ">=18.0.0"
|
|
156
156
|
},
|
|
157
157
|
"devDependencies": {
|
|
158
|
-
"@open-mercato/shared": "0.6.5-develop.
|
|
158
|
+
"@open-mercato/shared": "0.6.5-develop.4964.1.ae0edca575",
|
|
159
159
|
"@testing-library/dom": "^10.4.1",
|
|
160
160
|
"@testing-library/jest-dom": "^6.9.1",
|
|
161
161
|
"@testing-library/react": "^16.3.1",
|
|
@@ -3,6 +3,11 @@ import { useEffect, useState } from 'react'
|
|
|
3
3
|
import { apiCall } from '../../backend/utils/apiCall'
|
|
4
4
|
|
|
5
5
|
type OrgContext = {
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated The public org lookup no longer returns a tenant id; portal
|
|
8
|
+
* flows send `organizationId` and the server resolves the tenant. Always
|
|
9
|
+
* `undefined` — kept for backward compatibility with existing consumers.
|
|
10
|
+
*/
|
|
6
11
|
tenantId: string | undefined
|
|
7
12
|
organizationId: string | undefined
|
|
8
13
|
organizationName: string | undefined
|
|
@@ -49,7 +54,7 @@ export function useTenantContext(orgSlug: string): OrgContext {
|
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
try {
|
|
52
|
-
const { ok, result: data } = await apiCall<{ ok: boolean; organization: { id: string;
|
|
57
|
+
const { ok, result: data } = await apiCall<{ ok: boolean; organization: { id: string; name: string }; error?: string }>(`/api/directory/organizations/lookup?slug=${encodeURIComponent(orgSlug)}`)
|
|
53
58
|
if (cancelled) return
|
|
54
59
|
|
|
55
60
|
if (!ok || !data?.ok || !data.organization) {
|
|
@@ -62,7 +67,7 @@ export function useTenantContext(orgSlug: string): OrgContext {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
setState({
|
|
65
|
-
tenantId:
|
|
70
|
+
tenantId: undefined,
|
|
66
71
|
organizationId: data.organization.id,
|
|
67
72
|
organizationName: data.organization.name,
|
|
68
73
|
loading: false,
|