@adminide-stack/yantra-mobile 12.0.126 → 12.0.127-alpha.0
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,25 +1,22 @@
|
|
|
1
|
-
import {useEffect,useMemo}from'react';import {useSelector,useDispatch}from'react-redux';import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {useEffect,useMemo}from'react';import {useSelector,useDispatch}from'react-redux';import {userSelector,setUserAccountDetails}from'@adminide-stack/user-auth0-client';import {useAccountProfileQuery}from'common/graphql';import {pickPrimaryDisplayName,pickAuthPicture}from'../../utils/authUserDisplay.js';import {useYantraChatMembership}from'./useYantraChatMembership.js';import {YANTRA_CHAT_ORG_SLUG}from'./yantraChatOrg.js';function toRegistrationStatus(phoneE164, loading) {
|
|
2
|
+
if (phoneE164) return "registered";
|
|
3
|
+
return loading ? "registering" : "not-registered";
|
|
4
|
+
}
|
|
5
|
+
function describeAccountError(auth0Id, error) {
|
|
6
|
+
if (!auth0Id) return "You are signed out. Sign in again to use Chat.";
|
|
7
|
+
return error ? `Could not load your account: ${error.message}` : "Could not load your account.";
|
|
8
|
+
}
|
|
8
9
|
function useChatViewer() {
|
|
9
|
-
var _a, _b;
|
|
10
|
+
var _a, _b, _c;
|
|
10
11
|
const authUser = useSelector(userSelector);
|
|
11
12
|
const rehydrated = useSelector((state) => state._persist ? Boolean(state._persist.rehydrated) : true);
|
|
12
13
|
const dispatch = useDispatch();
|
|
13
14
|
const storedUserId = (authUser == null ? void 0 : authUser.id) || null;
|
|
14
15
|
const auth0Id = (authUser == null ? void 0 : authUser.authUserId) || null;
|
|
15
|
-
const account =
|
|
16
|
-
|
|
17
|
-
auth0Id
|
|
18
|
-
},
|
|
19
|
-
skip: !rehydrated || Boolean(storedUserId) || !auth0Id,
|
|
20
|
-
fetchPolicy: "network-only"
|
|
16
|
+
const account = useAccountProfileQuery({
|
|
17
|
+
skip: !rehydrated || Boolean(storedUserId) || !auth0Id
|
|
21
18
|
});
|
|
22
|
-
const recoveredUserId = ((_b = (_a = account.data) == null ? void 0 : _a.
|
|
19
|
+
const recoveredUserId = ((_c = (_b = (_a = account.data) == null ? void 0 : _a.accountProfile) == null ? void 0 : _b.user) == null ? void 0 : _c.id) || null;
|
|
23
20
|
useEffect(() => {
|
|
24
21
|
if (!storedUserId && recoveredUserId) dispatch(setUserAccountDetails({
|
|
25
22
|
id: recoveredUserId
|
|
@@ -29,7 +26,7 @@ function useChatViewer() {
|
|
|
29
26
|
const displayName = useMemo(() => pickPrimaryDisplayName(authUser), [authUser]);
|
|
30
27
|
const avatarUrl = useMemo(() => pickAuthPicture(authUser), [authUser]);
|
|
31
28
|
const membership = useYantraChatMembership(userId, displayName);
|
|
32
|
-
const registrationStatus = membership.phoneE164
|
|
29
|
+
const registrationStatus = toRegistrationStatus(membership.phoneE164, membership.loading);
|
|
33
30
|
const viewer = useMemo(() => userId ? {
|
|
34
31
|
userId,
|
|
35
32
|
displayName,
|
|
@@ -39,8 +36,7 @@ function useChatViewer() {
|
|
|
39
36
|
registrationStatus
|
|
40
37
|
} : null, [userId, displayName, avatarUrl, membership.phoneE164, registrationStatus]);
|
|
41
38
|
const ready = Boolean(authUser) && rehydrated && !membership.loading && !account.loading;
|
|
42
|
-
const
|
|
43
|
-
const error = membership.error || (!viewer && ready ? accountError : null);
|
|
39
|
+
const error = membership.error || (!viewer && ready ? describeAccountError(auth0Id, account.error) : null);
|
|
44
40
|
return {
|
|
45
41
|
viewer,
|
|
46
42
|
error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChatViewer.js","sources":["../../../src/features/messaging/useChatViewer.ts"],"sourcesContent":["import { useEffect, useMemo } from 'react';\nimport { useDispatch, useSelector } from 'react-redux';\nimport
|
|
1
|
+
{"version":3,"file":"useChatViewer.js","sources":["../../../src/features/messaging/useChatViewer.ts"],"sourcesContent":["import { useEffect, useMemo } from 'react';\nimport { useDispatch, useSelector } from 'react-redux';\nimport type { IUserState } from '@adminide-stack/core';\nimport { Store, setUserAccountDetails, userSelector } from '@adminide-stack/user-auth0-client';\nimport { useAccountProfileQuery } from 'common/graphql';\nimport { pickAuthPicture, pickPrimaryDisplayName } from '../../utils/authUserDisplay';\nimport type { ChatViewer, ChatRegistrationStatus } from './chatHost';\nimport { useYantraChatMembership } from './useYantraChatMembership';\nimport { YANTRA_CHAT_ORG_SLUG } from './yantraChatOrg';\n\nexport interface ChatViewerState {\n viewer: ChatViewer | null;\n error: string | null;\n ready: boolean;\n needsRegistration: boolean;\n membershipLoading: boolean;\n registerForChat: (phoneE164: string) => Promise<string>;\n refreshMembership: () => Promise<void>;\n}\n\nfunction toRegistrationStatus(phoneE164: string | null, loading: boolean): ChatRegistrationStatus {\n if (phoneE164) return 'registered';\n return loading ? 'registering' : 'not-registered';\n}\n\nfunction describeAccountError(auth0Id: string | null, error?: { message: string }): string {\n if (!auth0Id) return 'You are signed out. Sign in again to use Chat.';\n return error ? `Could not load your account: ${error.message}` : 'Could not load your account.';\n}\n\n/**\n * The account id for the signed-in user. The Login screen stores it in `user.id`, and the store is\n * persisted - so a session restored without it (an older build, or a lookup that failed at login)\n * keeps `id: ''` for good. Chat then asks the server for the session's own account, through the\n * same `accountProfile` query Home resolves it from (usePrerequisiteIds), so the cache is usually\n * warm by the time Chat opens.\n */\nexport function useChatViewer(): ChatViewerState {\n const authUser = useSelector<Store.Auth, IUserState>(userSelector);\n // The store is restored from disk after launch (redux-persist, no gate in front of the UI):\n // until then `user` is the empty initial state, which must not read as \"no account\".\n const rehydrated = useSelector((state: { _persist?: { rehydrated?: boolean } }) =>\n state._persist ? Boolean(state._persist.rehydrated) : true,\n );\n const dispatch = useDispatch();\n const storedUserId = authUser?.id || null;\n const auth0Id = (authUser as { authUserId?: string | null } | undefined)?.authUserId || null;\n\n const account = useAccountProfileQuery({\n skip: !rehydrated || Boolean(storedUserId) || !auth0Id,\n });\n const recoveredUserId = account.data?.accountProfile?.user?.id || null;\n\n // Repair the store, so every screen reading `user.id` (not only Chat) gets the account.\n useEffect(() => {\n if (!storedUserId && recoveredUserId) dispatch(setUserAccountDetails({ id: recoveredUserId }));\n }, [storedUserId, recoveredUserId, dispatch]);\n\n const userId = storedUserId || recoveredUserId;\n const displayName = useMemo(() => pickPrimaryDisplayName(authUser), [authUser]);\n const avatarUrl = useMemo(() => pickAuthPicture(authUser), [authUser]);\n\n const membership = useYantraChatMembership(userId, displayName);\n\n const registrationStatus = toRegistrationStatus(membership.phoneE164, membership.loading);\n\n const viewer = useMemo<ChatViewer | null>(\n () =>\n userId\n ? {\n userId,\n displayName,\n avatarUrl,\n orgName: YANTRA_CHAT_ORG_SLUG,\n phoneE164: membership.phoneE164,\n registrationStatus,\n }\n : null,\n [userId, displayName, avatarUrl, membership.phoneE164, registrationStatus],\n );\n\n const ready = Boolean(authUser) && rehydrated && !membership.loading && !account.loading;\n\n const error = membership.error || (!viewer && ready ? describeAccountError(auth0Id, account.error) : null);\n\n return {\n viewer,\n error,\n ready,\n needsRegistration: membership.needsRegistration,\n membershipLoading: membership.loading,\n registerForChat: membership.register,\n refreshMembership: membership.refresh,\n };\n}\n"],"names":[],"mappings":"4aAkBA,SAAS,oBAAA,CAAqB,WAA0B,OAA0C,EAAA;AAChG,EAAA,IAAI,WAAkB,OAAA,YAAA;AACtB,EAAA,OAAO,UAAU,aAAgB,GAAA,gBAAA;AACnC;AACA,SAAS,oBAAA,CAAqB,SAAwB,KAE3C,EAAA;AACT,EAAI,IAAA,CAAC,SAAgB,OAAA,gDAAA;AACrB,EAAA,OAAO,KAAQ,GAAA,CAAA,6BAAA,EAAgC,KAAM,CAAA,OAAO,CAAK,CAAA,GAAA,8BAAA;AACnE;AASO,SAAS,aAAiC,GAAA;AApCjD,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAqCE,EAAM,MAAA,QAAA,GAAW,YAAoC,YAAY,CAAA;AAGjE,E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OAAO,CAAA;AACxF,EAAM,MAAA,MAAA,GAAS,OAA2B,CAAA,MAAM,MAAS,GAAA;AAAA,IACvD,MAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAS,EAAA,oBAAA;AAAA,IACT,WAAW,UAAW,CAAA,SAAA;AAAA,IACtB;AAAA,GACF,GAAI,MAAM,CAAC,MAAA,EAAQ,aAAa,SAAW,EAAA,UAAA,CAAW,SAAW,EAAA,kBAAkB,CAAC,CAAA;AACpF,EAAM,MAAA,KAAA,GAAQ,QAAQ,QAAQ,CAAA,IAAK,cAAc,CAAC,UAAA,CAAW,OAAW,IAAA,CAAC,OAAQ,CAAA,OAAA;AACjF,EAAM,MAAA,KAAA,GAAQ,UAAW,CAAA,KAAA,KAAU,CAAC,MAAA,IAAU,QAAQ,oBAAqB,CAAA,OAAA,EAAS,OAAQ,CAAA,KAAK,CAAI,GAAA,IAAA,CAAA;AACrG,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,mBAAmB,UAAW,CAAA,iBAAA;AAAA,IAC9B,mBAAmB,UAAW,CAAA,OAAA;AAAA,IAC9B,iBAAiB,UAAW,CAAA,QAAA;AAAA,IAC5B,mBAAmB,UAAW,CAAA;AAAA,GAChC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminide-stack/yantra-mobile",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.127-alpha.0",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"uuid": "^9.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"common": "12.0.
|
|
30
|
+
"common": "12.0.127-alpha.0",
|
|
31
31
|
"libphonenumber-js": "^1.13.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@messenger-box/platform-mobile": "*",
|
|
46
46
|
"@react-native-async-storage/async-storage": "*",
|
|
47
47
|
"@react-navigation/native": "*",
|
|
48
|
-
"common": "12.0.125",
|
|
48
|
+
"common": "12.0.125-alpha.0",
|
|
49
49
|
"expo-background-task": "*",
|
|
50
50
|
"expo-constants": "*",
|
|
51
51
|
"expo-secure-store": "*",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"typescript": {
|
|
68
68
|
"definition": "lib/index.d.ts"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "f0e3917d46211415b206400ed76d88fa9b2f1d31"
|
|
71
71
|
}
|