From 2e38e7c1dabfd7f1614c96219b7abbd166ef0490 Mon Sep 17 00:00:00 2001 From: NishilJ <78994772+NishilJ@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:13:24 -0600 Subject: [PATCH] Merge branch 'AccountUpdate' --- src/components/AccountUpdate.tsx | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/components/AccountUpdate.tsx diff --git a/src/components/AccountUpdate.tsx b/src/components/AccountUpdate.tsx new file mode 100644 index 0000000..b7abfac --- /dev/null +++ b/src/components/AccountUpdate.tsx @@ -0,0 +1,88 @@ +import React, { useState, useEffect } from 'react'; +import { updateProfile, updateEmail } from 'firebase/auth'; +import { auth } from '../firebaseconfig'; +import { + Button, + TextField, + Heading, + View, + Flex, + Divider, + Provider, + defaultTheme +} from '@adobe/react-spectrum'; + +const AccountUpdate: React.FC = () => { + const [firstName, setFirstName] = useState(''); + const [lastName, setLastName] = useState(''); + const [email, setEmail] = useState(''); + const [phone, setPhone] = useState(''); + + useEffect(() => { + const user = auth.currentUser; + if (user) { + // Populate fields with the current user data + setFirstName(user.displayName?.split(' ')[0] || ''); + setLastName(user.displayName?.split(' ')[1] || ''); + setEmail(user.email || ''); + } + }, []); + + const handleUpdate = async () => { + const user = auth.currentUser; + if (user) { + try { + // Update display name + await updateProfile(user, { + displayName: `${firstName} ${lastName}` + }); + + // Update email + if (email !== user.email) { + await updateEmail(user, email); + } + + alert('Account information updated successfully.'); + } catch (error) { + console.error("Error updating account information:", error); + alert((error as Error).message); + } + } + }; + + return ( + + + Account Settings + + + + + + + + + + + ); +}; + +export default AccountUpdate;