diff --git a/src/app/me/AboutMe.tsx b/src/app/me/AboutMe.tsx index 4fce5b7..85df785 100644 --- a/src/app/me/AboutMe.tsx +++ b/src/app/me/AboutMe.tsx @@ -14,21 +14,13 @@ import { passwordUpdateSchema } from "@/schemas"; import PrettyForm from "@/components/PrettyForm"; +import Toast from "@/components/Toast"; type UpdateResponse = { ok: boolean; error?: string; }; -// TODO skip do your magic -type InputProps = { - label: string; - name: string; - type: HTMLInputTypeAttribute; - error?: string; - displayImage?: string; -} & InputHTMLAttributes; - async function fileAsBase64(f: File) { const reader = new FileReader(); reader.readAsArrayBuffer(f); @@ -44,6 +36,9 @@ async function fileAsBase64(f: File) { export default function AboutMe({ info }: { info: UserInfo }) { const [globalError, setGlobalError] = React.useState(null); + const [madeProfileChanges, setMadeChanges] = React.useState(false); + const [madePasswordChanges, setMadePasswordChanges] = React.useState(false); + const initialValues: AboutMeFormValues = { username: info.username, displayName: info.displayName, @@ -55,6 +50,7 @@ export default function AboutMe({ info }: { info: UserInfo }) { { displayName, email, avatar }: AboutMeFormValues, { setSubmitting }: FormikHelpers ) { + setMadeChanges(false); setSubmitting(true); const req = await fetch("/api/update", { method: "POST", @@ -78,6 +74,7 @@ export default function AboutMe({ info }: { info: UserInfo }) { break; } } + setMadeChanges(true); } catch { console.error(req); } @@ -94,7 +91,7 @@ export default function AboutMe({ info }: { info: UserInfo }) { { password, newPassword }: PasswordUpdateFormValues, { setFieldError, setSubmitting }: FormikHelpers ) { - console.log(password, newPassword); + setMadePasswordChanges(false); setSubmitting(true); const req = await fetch("/api/changePassword", { method: "POST", @@ -118,6 +115,7 @@ export default function AboutMe({ info }: { info: UserInfo }) { break; } } + setMadePasswordChanges(true); } catch { console.error(req); } @@ -134,6 +132,7 @@ export default function AboutMe({ info }: { info: UserInfo }) { > {({ isSubmitting }) => (
+ {madeProfileChanges ? Saved your changes. : null} -

Change password

@@ -190,7 +188,10 @@ export default function AboutMe({ info }: { info: UserInfo }) { validationSchema={passwordUpdateSchema} > {({ isSubmitting }) => ( - + + {madePasswordChanges ? ( + Changed your password. + ) : null} -
+ + {children} + + ); +} diff --git a/src/components/icons/CheckIcon.tsx b/src/components/icons/CheckIcon.tsx new file mode 100644 index 0000000..17c727e --- /dev/null +++ b/src/components/icons/CheckIcon.tsx @@ -0,0 +1,19 @@ +export default function CheckIcon() { + return ( + + + + + + + + ); +}