|
1 | 1 |
|
2 | 2 | import { useRef } from 'react'; |
3 | 3 | import { NavLink } from 'react-router-dom'; |
4 | | -import { actionPostFile } from '../../actions'; |
| 4 | +import { toast } from 'react-toastify'; |
| 5 | +import { actionUploadPushFirebaseServiceAccount } from '../../actions'; |
5 | 6 | import { IconUpload } from '../../components/Icons/IconUpload'; |
6 | 7 |
|
7 | 8 | interface Props { |
8 | 9 | appId: string; |
9 | | - setGoogleServicesJson: (s: string) => void; |
10 | 10 | primaryColor: string; |
11 | 11 | } |
12 | 12 |
|
13 | 13 | export function MobileApp({ |
14 | 14 | appId, |
15 | | - setGoogleServicesJson, |
16 | 15 | primaryColor, |
17 | 16 | }: Props) { |
18 | | - const googleJsonRef = useRef<HTMLInputElement>(null); |
| 17 | + const pushServiceAccountRef = useRef<HTMLInputElement>(null); |
19 | 18 |
|
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 | + }); |
28 | 33 | }; |
29 | 34 |
|
30 | 35 | return ( |
@@ -108,20 +113,20 @@ export function MobileApp({ |
108 | 113 | Push Notifications |
109 | 114 | </div> |
110 | 115 | <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. |
112 | 117 | </p> |
113 | 118 | <input |
114 | 119 | type="file" |
115 | | - ref={googleJsonRef} |
| 120 | + ref={pushServiceAccountRef} |
116 | 121 | accept=".json" |
117 | 122 | className="hidden" |
118 | 123 | onChange={(e) => |
119 | | - onGoogleJsonRefChanges(e.target.files && e.target.files[0]) |
| 124 | + onPushServiceAccountChanges(e.target.files && e.target.files[0]) |
120 | 125 | } |
121 | 126 | /> |
122 | 127 | <button |
123 | 128 | 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()} |
125 | 130 | > |
126 | 131 | <IconUpload stroke={primaryColor}></IconUpload> |
127 | 132 | <span className="ml-2">Upload</span> |
|
0 commit comments