Skip to content

Commit 05acb37

Browse files
committed
fix(settings): restore preserved mobile push and base app UX
Carry over the safe preserved frontend changes by uploading push Firebase credentials directly per app and by showing clearer chat context guidance when an admin is in the base app.
1 parent 393e057 commit 05acb37

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

src/actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
httpGetConfig,
88
httpGetUsers,
99
httpPostFile,
10+
httpUploadPushFirebaseServiceAccount,
1011
httpResetPasswords,
1112
httpTokens,
1213
httpUpdateApp,
@@ -166,6 +167,13 @@ export async function actionPostFile(file: File) {
166167
return httpPostFile(file);
167168
}
168169

170+
export async function actionUploadPushFirebaseServiceAccount(
171+
appId: string,
172+
file: File
173+
) {
174+
return httpUploadPushFirebaseServiceAccount(appId, file);
175+
}
176+
169177
export async function actionGetUsers(
170178
appId: string,
171179
limit: number = 10,

src/http.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ export function httpPostFile(file: File) {
207207
return http.post('/files', fd);
208208
}
209209

210+
export function httpUploadPushFirebaseServiceAccount(appId: string, file: File) {
211+
const fd = new FormData();
212+
fd.append('firebaseServiceAccount', file);
213+
return http.post(`/push/firebase-service-account/${appId}`, fd);
214+
}
215+
210216
export function httpGetUsers(
211217
appId: string,
212218
limit: number = 10,

src/pages/AppSettings/AppSettings.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ export default function AppSettings() {
714714
<MobileApp
715715
appId={appId as string}
716716
primaryColor={app.primaryColor}
717-
setGoogleServicesJson={setGoogleServicesJson}
718717
/>
719718
</TabPanel>
720719

src/pages/AppSettings/MobileApp.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11

22
import { useRef } from 'react';
33
import { NavLink } from 'react-router-dom';
4-
import { actionPostFile } from '../../actions';
4+
import { toast } from 'react-toastify';
5+
import { actionUploadPushFirebaseServiceAccount } from '../../actions';
56
import { IconUpload } from '../../components/Icons/IconUpload';
67

78
interface Props {
89
appId: string;
9-
setGoogleServicesJson: (s: string) => void;
1010
primaryColor: string;
1111
}
1212

1313
export function MobileApp({
1414
appId,
15-
setGoogleServicesJson,
1615
primaryColor,
1716
}: Props) {
18-
const googleJsonRef = useRef<HTMLInputElement>(null);
17+
const pushServiceAccountRef = useRef<HTMLInputElement>(null);
1918

20-
const onGoogleJsonRefChanges = (file: File | null) => {
21-
if (!file) {
22-
return;
23-
}
24-
25-
actionPostFile(file).then((resp) => {
26-
setGoogleServicesJson(resp.data.results[0].location);
27-
});
19+
const onPushServiceAccountChanges = (file: File | null) => {
20+
if (!file) return;
21+
actionUploadPushFirebaseServiceAccount(appId, file)
22+
.then(() => {
23+
toast.success('Push service account uploaded');
24+
})
25+
.catch((e) => {
26+
const msg =
27+
e?.response?.data?.error ||
28+
e?.response?.data?.details ||
29+
e?.message ||
30+
'Failed to upload push service account';
31+
toast.error(String(msg));
32+
});
2833
};
2934

3035
return (
@@ -108,20 +113,20 @@ export function MobileApp({
108113
Push Notifications
109114
</div>
110115
<p className="font-sans text-sm leading-relaxed mb-4">
111-
Follow <a href="https://forum.ethora.com/topic/75-setting-up-push-notifications-for-your-ethora-chats/" target="_blank" rel="noopener noreferrer" className="text-blue-600 underline">this manual</a> to set up your Firebase account. Extract and upload your <strong>service-account.json</strong>. This will enable your users to receive push notifications for chat messages they missed while being offline.
116+
Follow <a href="https://forum.ethora.com/topic/75-setting-up-push-notifications-for-your-ethora-chats/" target="_blank" rel="noopener noreferrer" className="text-blue-600 underline">this manual</a> to set up your Firebase account. Upload your <strong>service-account.json</strong> here to enable push notifications for offline chat messages.
112117
</p>
113118
<input
114119
type="file"
115-
ref={googleJsonRef}
120+
ref={pushServiceAccountRef}
116121
accept=".json"
117122
className="hidden"
118123
onChange={(e) =>
119-
onGoogleJsonRefChanges(e.target.files && e.target.files[0])
124+
onPushServiceAccountChanges(e.target.files && e.target.files[0])
120125
}
121126
/>
122127
<button
123128
className="w-full hover:bg-brand-hover rounded-xl border border-brand-500 text-brand-500 flex p-2 items-center justify-center mb-8"
124-
onClick={() => googleJsonRef.current?.click()}
129+
onClick={() => pushServiceAccountRef.current?.click()}
125130
>
126131
<IconUpload stroke={primaryColor}></IconUpload>
127132
<span className="ml-2">Upload</span>

src/pages/Chat.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,41 @@ const MemoizedChat = React.memo(function ChatComponent({
8585
export default function ChatPage() {
8686
const config = useAppStore((s) => s.currentApp);
8787
const isAdmin = useAppStore((s) => s.currentApp?.isAllowedNewAppCreate);
88+
const apps = useAppStore((s) => s.apps);
8889

8990
const { currentUser } = useAppStore((s) => s);
9091

9192
const allowedDomains =
9293
import.meta.env.VITE_APP_ALLOWED_DOMAINS?.split(',') || [];
9394
const currentDomain = window.location.hostname;
95+
const isDemoDomain = allowedDomains.includes(currentDomain);
96+
const isBaseApp = Boolean(config?.isBaseApp);
97+
const hasOtherApps = Array.isArray(apps)
98+
? apps.some((app) => app && app._id !== config?._id && !app.isBaseApp)
99+
: false;
100+
const showBaseAppContextBanner = Boolean(
101+
isAdmin && isBaseApp && (isDemoDomain || hasOtherApps)
102+
);
94103

95104
return (
96105
<div className="grid grid-rows-[auto,_1fr] gap-4 h-full abc">
97106
<div className="md:px-8 hidden md:flex flex-col justify-between items-stretch md:items-center md:flex-row">
98107
<div className="font-varela mb-4 text-[24px] md:mb-0 md:text-[34px] leading-none">
99108
Chats
100109
</div>
101-
{isAdmin && allowedDomains.includes(currentDomain) && (
110+
{showBaseAppContextBanner && (
102111
<div className="flex flex-col items-center bg-yellow-100 px-4 py-2 text-sm border">
103-
<p>This is demo server</p>
112+
{isDemoDomain ? (
113+
<p>This is a demo server</p>
114+
) : (
115+
<p>This is the Base App context</p>
116+
)}
104117
<p className="flex items-center gap-2">
105-
<span>To test your own App, go to "Admin"</span>
118+
<span>
119+
{isDemoDomain
120+
? 'To test your own App, go to "Admin"'
121+
: 'To switch context, go to "Admin"'}
122+
</span>
106123
<ArrowRightAltIcon /> <span>your App </span>
107124
<ArrowRightAltIcon /> <span>"Publish"</span>
108125
</p>

0 commit comments

Comments
 (0)