From 2374e80380e968a2955e1d5f6b1faf17577eaea2 Mon Sep 17 00:00:00 2001 From: Beilin-b Date: Thu, 16 Jul 2026 09:40:51 -0700 Subject: [PATCH] =?UTF-8?q?GetPlatformNumber=E2=80=8B=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/settings/page.js | 132 +++++++++++++------------------------------ 1 file changed, 40 insertions(+), 92 deletions(-) diff --git a/app/settings/page.js b/app/settings/page.js index 21a4113..01c7915 100644 --- a/app/settings/page.js +++ b/app/settings/page.js @@ -23,7 +23,7 @@ import { import { useTranslation } from 'react-i18next'; import toast, { Toaster } from 'react-hot-toast'; import AuthService from '../services/AuthService'; -import { changePassword, deleteMyAccount, submitReport } from '../utils/api'; +import { deleteMyAccount } from '../utils/api'; export default function SettingsPage() { const { t, i18n } = useTranslation(); @@ -31,12 +31,6 @@ export default function SettingsPage() { const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [deletePassword, setDeletePassword] = useState(''); const [isDeleting, setIsDeleting] = useState(false); - const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); - - const [showContactDialog, setShowContactDialog] = useState(false); - const [contactSubject, setContactSubject] = useState(''); - const [contactBody, setContactBody] = useState(''); - const [isSendingContact, setIsSendingContact] = useState(false); const handleSignOut = () => { AuthService.deleteToken(); @@ -65,23 +59,45 @@ export default function SettingsPage() { } }; - const handleSendContact = async () => { - if (!contactSubject.trim() || !contactBody.trim()) { - toast.error(t('fill-subject-and-message')); - return; - } - - setIsSendingContact(true); + const handleContactSupport = async () => { try { - await submitReport(contactSubject.trim(), contactBody.trim()); - toast.success(t('send-success')); - setShowContactDialog(false); - setContactSubject(''); - setContactBody(''); + let token = ''; + if (typeof AuthService.getToken === 'function') { + token = AuthService.getToken(); + } else if (typeof window !== 'undefined') { + token = localStorage.getItem('token') || localStorage.getItem('accessToken') || ''; + } + + const response = await fetch('http://45.93.137.91/api/Configuration/GetPlatformNumber', { + method: 'GET', + headers: { + 'Authorization': `Bearer ${token}` + } + }); + + if (!response.ok) { + throw new Error('Failed to fetch support number'); + } + + const responseText = await response.text(); + let numberStr = responseText; + + try { + const parsed = JSON.parse(responseText); + numberStr = parsed.data || parsed.number || parsed.value || parsed; + } catch (e) {} + + const cleanNumber = typeof numberStr === 'string' + ? numberStr.replace(/[^0-9+]/g, '') + : String(numberStr).replace(/[^0-9+]/g, ''); + + if (cleanNumber) { + window.location.href = `https://wa.me/${cleanNumber}`; + } else { + toast.error(t('error')); + } } catch (err) { - toast.error(err.message || t('send-error')); - } finally { - setIsSendingContact(false); + toast.error(t('error')); } }; @@ -104,7 +120,7 @@ export default function SettingsPage() { title: t('support'), items: [ { icon: HelpCircle, label: t('faq'), href: '/faq', desc: t('faq-desc') }, - { icon: MessageCircle, label: t('contactUs'), desc: t('contact-us-desc'), action: () => setShowContactDialog(true) }, + { icon: MessageCircle, label: t('contactUs'), desc: t('contact-us-desc'), action: handleContactSupport }, { icon: FileText, label: t('terms-and-conditions'), href: '/terms', desc: t('terms-desc') }, { icon: Eye, label: t('privacy'), href: '/privacy', desc: t('privacy-desc') }, ] @@ -289,74 +305,6 @@ export default function SettingsPage() { )} - - {showContactDialog && ( -
- -
-
- -
-
-

{t('contactUs')}

-

{t('contact-reply-prompt')}

-
- -
- - setContactSubject(e.target.value)} - placeholder={t('subject')} - maxLength={300} - className="w-full px-4 py-3 border border-gray-300 rounded-xl mb-4 focus:ring-2 focus:ring-amber-500 focus:border-transparent outline-none" - /> - -