fix(client): test-notification button on /client sends push directly (url → /client/test-consent), no detour via /client/test
This commit is contained in:
parent
91245169f4
commit
fee800e3fa
|
|
@ -17,6 +17,70 @@ import {
|
|||
fetchDeliveryInvitation,
|
||||
} from "../services/deliveryInvitationApi";
|
||||
|
||||
const SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL || "";
|
||||
const SUPABASE_ANON_KEY = import.meta.env.VITE_SUPABASE_ANON_KEY || "";
|
||||
|
||||
const TestPushButton = () => {
|
||||
const [sending, setSending] = React.useState(false);
|
||||
const [sendResult, setSendResult] = React.useState(null); // null | {ok, sent, error}
|
||||
|
||||
const handleClick = async () => {
|
||||
setSending(true);
|
||||
setSendResult(null);
|
||||
try {
|
||||
const phone = window.localStorage.getItem("supersam_phone") || "";
|
||||
if (!phone) {
|
||||
setSendResult({ ok: false, error: "Сначала подпишитесь на уведомления (кнопка «Разрешить» выше)" });
|
||||
return;
|
||||
}
|
||||
const resp = await fetch(`${SUPABASE_URL}/functions/v1/send-test-push`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(SUPABASE_ANON_KEY ? { apikey: SUPABASE_ANON_KEY } : {}),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
phone_normalized: phone,
|
||||
title: "СуперСам — согласуйте доставку",
|
||||
body: "Ваш заказ готов к доставке. Выберите удобное время.",
|
||||
url: `${window.location.origin}/client/test-consent`,
|
||||
}),
|
||||
});
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
setSendResult({ ok: resp.ok, ...data });
|
||||
} catch (e) {
|
||||
setSendResult({ ok: false, error: e instanceof Error ? e.message : "Ошибка отправки" });
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
disabled={sending}
|
||||
className="rounded-xl bg-[var(--color-accent)] px-4 py-2 text-sm font-semibold text-white transition hover:opacity-90 disabled:opacity-50"
|
||||
>
|
||||
{sending ? "Отправляем…" : "Отправить тестовое уведомление"}
|
||||
</button>
|
||||
|
||||
{sendResult?.ok ? (
|
||||
<p className="text-sm text-[var(--color-accent)]">
|
||||
✅ Отправлено: {sendResult.sent} уведомление(й). Проверьте телефон.
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{sendResult && !sendResult.ok ? (
|
||||
<p className="text-sm text-[var(--color-danger)]">
|
||||
❌ {sendResult.error || "Не удалось отправить уведомление"}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const DELIVERY_TIMEZONE = "Europe/Simferopol";
|
||||
|
||||
const getBusinessTodayKey = (referenceDate = new Date()) => {
|
||||
|
|
@ -372,16 +436,11 @@ export const ClientDeliveryPage = () => {
|
|||
<div>
|
||||
<p className="text-sm font-semibold text-[var(--color-text)]">🧪 Тест уведомления</p>
|
||||
<p className="text-xs text-[var(--color-text-muted)] mt-1 leading-5">
|
||||
Отправить тестовое push-уведомление (после подписки). Нажмите на уведомление —
|
||||
Отправить тестовое push-уведомление на этот телефон. Нажмите на уведомление —
|
||||
откроется тестовая страница согласования доставки.
|
||||
</p>
|
||||
</div>
|
||||
<a
|
||||
href="/client/test"
|
||||
className="inline-block rounded-xl bg-[var(--color-accent)] px-4 py-2 text-sm font-semibold text-white transition hover:opacity-90"
|
||||
>
|
||||
Открыть тестовую страницу
|
||||
</a>
|
||||
<TestPushButton />
|
||||
</Panel>
|
||||
|
||||
<div className="text-center">
|
||||
|
|
|
|||
Loading…
Reference in New Issue