feat: push notifikace pro připomínku výběru oběda
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful
This commit is contained in:
@@ -3,6 +3,7 @@ import { Modal, Button, Form } from "react-bootstrap"
|
||||
import { useSettings, ThemePreference } from "../../context/settings";
|
||||
import { NotificationSettings, UdalostEnum, getNotificationSettings, updateNotificationSettings } from "../../../../types";
|
||||
import { useAuth } from "../../context/auth";
|
||||
import { subscribeToPush, unsubscribeFromPush } from "../../hooks/usePushReminder";
|
||||
|
||||
type Props = {
|
||||
isOpen: boolean,
|
||||
@@ -19,6 +20,7 @@ export default function SettingsModal({ isOpen, onClose, onSave }: Readonly<Prop
|
||||
const hideSoupsRef = useRef<HTMLInputElement>(null);
|
||||
const themeRef = useRef<HTMLSelectElement>(null);
|
||||
|
||||
const reminderTimeRef = useRef<HTMLSelectElement>(null);
|
||||
const ntfyTopicRef = useRef<HTMLInputElement>(null);
|
||||
const discordWebhookRef = useRef<HTMLInputElement>(null);
|
||||
const teamsWebhookRef = useRef<HTMLInputElement>(null);
|
||||
@@ -43,6 +45,9 @@ export default function SettingsModal({ isOpen, onClose, onSave }: Readonly<Prop
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
const newReminderTime = reminderTimeRef.current?.value || undefined;
|
||||
const oldReminderTime = notifSettings.reminderTime;
|
||||
|
||||
// Uložení notifikačních nastavení na server
|
||||
await updateNotificationSettings({
|
||||
body: {
|
||||
@@ -50,9 +55,17 @@ export default function SettingsModal({ isOpen, onClose, onSave }: Readonly<Prop
|
||||
discordWebhookUrl: discordWebhookRef.current?.value || undefined,
|
||||
teamsWebhookUrl: teamsWebhookRef.current?.value || undefined,
|
||||
enabledEvents,
|
||||
reminderTime: newReminderTime,
|
||||
}
|
||||
}).catch(() => {});
|
||||
|
||||
// Správa push subscription pro připomínky
|
||||
if (newReminderTime && newReminderTime !== oldReminderTime) {
|
||||
subscribeToPush(newReminderTime);
|
||||
} else if (!newReminderTime && oldReminderTime) {
|
||||
unsubscribeFromPush();
|
||||
}
|
||||
|
||||
// Uložení ostatních nastavení (localStorage)
|
||||
onSave(
|
||||
bankAccountRef.current?.value,
|
||||
@@ -102,6 +115,29 @@ export default function SettingsModal({ isOpen, onClose, onSave }: Readonly<Prop
|
||||
Nastavením notifikací budete dostávat upozornění o událostech (např. "Jdeme na oběd") přímo do vámi zvoleného komunikačního kanálu.
|
||||
</p>
|
||||
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>Připomínka výběru oběda</Form.Label>
|
||||
<Form.Select
|
||||
ref={reminderTimeRef}
|
||||
defaultValue={notifSettings.reminderTime ?? ''}
|
||||
key={notifSettings.reminderTime ?? 'reminder-empty'}
|
||||
>
|
||||
<option value="">Vypnuto</option>
|
||||
<option value="10:00">10:00</option>
|
||||
<option value="10:30">10:30</option>
|
||||
<option value="11:00">11:00</option>
|
||||
<option value="11:30">11:30</option>
|
||||
<option value="12:00">12:00</option>
|
||||
<option value="12:30">12:30</option>
|
||||
<option value="13:00">13:00</option>
|
||||
<option value="13:30">13:30</option>
|
||||
<option value="14:00">14:00</option>
|
||||
</Form.Select>
|
||||
<Form.Text className="text-muted">
|
||||
V zadaný čas vám přijde push notifikace, pokud nemáte zvolenou možnost stravování.
|
||||
</Form.Text>
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group className="mb-3">
|
||||
<Form.Label>ntfy téma (topic)</Form.Label>
|
||||
<Form.Control
|
||||
|
||||
Reference in New Issue
Block a user