-
- {notificationTypes.map(({type, question}) => (
- {
- setPrefs((prevPrefs) => ({...prevPrefs, [type]: selected}))
- }}
- />
- ))}
-
-
- )
-}
-
-const NotificationOption = (props: {
- type: notification_preference
- question: string
- selected: notification_destination_types[]
- onUpdate: (selected: notification_destination_types[]) => void
+const GeneralSettings = (props: {
+ privateUser: PrivateUser,
+ user: User,
}) => {
- const {type, question, selected, onUpdate} = props
+ const {privateUser, user} = props
- const getSelectedValues = (destinations: string[]) => {
- const values: number[] = []
- if ((destinations ?? []).includes('email')) values.push(0)
- if ((destinations ?? []).includes('browser')) values.push(1)
- return values
- }
-
- const setValue = async (value: number[]) => {
- const newDestinations: notification_destination_types[] = []
- if (value.includes(0)) newDestinations.push('email')
- if (value.includes(1)) newDestinations.push('browser')
-
- onUpdate(newDestinations)
- save(selected, newDestinations)
- }
-
- const save = useCallback(
- debounce(
- (
- oldDestinations: notification_destination_types[],
- newDestinations: notification_destination_types[]
- ) => {
- // for each medium, if it changed, trigger a save
- const mediums = ['email', 'browser'] as const
- mediums.forEach((medium) => {
- const wasEnabled = oldDestinations.includes(medium)
- const isEnabled = newDestinations.includes(medium)
- if (wasEnabled !== isEnabled) {
- api('update-notif-settings', {
- type,
- medium,
- enabled: isEnabled,
- })
- }
+ const handleDeleteAccount = async () => {
+ const confirmed = confirm(
+ 'Are you sure you want to delete your profile? This cannot be undone.'
+ )
+ if (confirmed) {
+ toast
+ .promise(deleteAccount(), {
+ loading: 'Deleting account...',
+ success: () => {
+ router.push('/')
+ return 'Your account has been deleted.'
+ },
+ error: () => {
+ return 'Failed to delete account.'
+ },
})
- },
- 500
- ),
- []
- )
+ .catch(() => {
+ console.log("Failed to delete account")
+ })
+ }
+ }
- return (
-
-
{question}
-
+ const sendPasswordReset = async () => {
+ if (!privateUser?.email) {
+ toast.error('No email found on your account.')
+ return
+ }
+ const auth = getAuth()
+ toast.promise(
+ sendPasswordResetEmail(auth, privateUser.email),
+ {
+ loading: 'Sending password reset email...',
+ success: 'Password reset email sent — check your inbox and spam.',
+ error: 'Failed to send password reset email.',
+ }
+ )
+ .catch(() => {
+ console.log("Failed to send password reset email")
+ })
+ }
+
+ const sendVerificationEmail = async () => {
+ if (!privateUser?.email) {
+ toast.error('No email found on your account.')
+ return
+ }
+ if (!user) {
+ toast.error('You must be signed in to send a verification email.')
+ return
+ }
+ toast
+ .promise(sendEmailVerification(user), {
+ loading: 'Sending verification email...',
+ success: 'Verification email sent — check your inbox and spam.',
+ error: 'Failed to send verification email.',
+ })
+ .catch(() => {
+ console.log("Failed to send verification email")
+ })
+ }
+
+ const isEmailVerified = user.emailVerified
+
+ return <>
+
+
Theme
+
+ Account
+ Credentials
+
+
+ Verification
+
+
+ Dangerous
+
- )
+ >
}
+