Fix more bugs with lunch reminder

This commit is contained in:
2025-09-17 16:40:38 -05:00
parent d4842fdacd
commit 3bff31c07a
3 changed files with 16 additions and 6 deletions

View File

@@ -49,9 +49,9 @@ const RootLayout = async ({
<TVModeProvider> <TVModeProvider>
<Header /> <Header />
{children} {children}
<Toaster />
<NotificationsPermission /> <NotificationsPermission />
<LunchReminder /> <LunchReminder />
<Toaster />
</TVModeProvider> </TVModeProvider>
</ConvexClientProvider> </ConvexClientProvider>
</ThemeProvider> </ThemeProvider>

View File

@@ -1,5 +1,5 @@
'use client'; 'use client';
import { useState } from 'react'; import { useMemo, useState } from 'react';
import { type Preloaded, usePreloadedQuery, useMutation } from 'convex/react'; import { type Preloaded, usePreloadedQuery, useMutation } from 'convex/react';
import { api } from '~/convex/_generated/api'; import { api } from '~/convex/_generated/api';
import { z } from 'zod'; import { z } from 'zod';
@@ -50,13 +50,17 @@ export const UserInfoForm = ({ preloadedUser }: UserInfoFormProps) => {
const updateUserEmail = useMutation(api.auth.updateUserEmail); const updateUserEmail = useMutation(api.auth.updateUserEmail);
const updateUserLunchtime = useMutation(api.auth.updateUserLunchtime); const updateUserLunchtime = useMutation(api.auth.updateUserLunchtime);
const form = useForm<z.infer<typeof formSchema>>({ const initialValues = useMemo<z.infer<typeof formSchema>>(
resolver: zodResolver(formSchema), () => ({
defaultValues: {
name: user?.name ?? '', name: user?.name ?? '',
email: user?.email ?? '', email: user?.email ?? '',
lunchTime: user?.lunchTime ?? '', lunchTime: user?.lunchTime ?? '',
}, }), [user?.name, user?.email, user?.lunchTime]
);
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
values: initialValues,
}); });
const handleSubmit = async (values: z.infer<typeof formSchema>) => { const handleSubmit = async (values: z.infer<typeof formSchema>) => {

View File

@@ -1,5 +1,6 @@
'use client'; 'use client';
import { permission } from 'process';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { toast } from 'sonner'; import { toast } from 'sonner';
@@ -12,6 +13,11 @@ export const NotificationsPermission = () => {
// Only ask once; tweak logic to your taste. // Only ask once; tweak logic to your taste.
const prompted = localStorage.getItem(STORAGE_KEY) === '1'; const prompted = localStorage.getItem(STORAGE_KEY) === '1';
console.log('NotificationsPermission', {
supported: true,
permission: Notification.permission,
prompted,
});
if (prompted) return; if (prompted) return;
if (Notification.permission === 'default') { if (Notification.permission === 'default') {