Skip to content

Commit

Permalink
Add toast notifications for profile update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu committed Dec 11, 2023
1 parent a5c4dc9 commit e995215
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
11 changes: 11 additions & 0 deletions apps/passport/app/components/EditProfileModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Input } from '@proofzero/design-system/src/atoms/form/Input'
import { captureFormSubmitAndReplaceImages } from '@proofzero/design-system/src/utils/form-cf-images'
import { Loader } from '@proofzero/design-system/src/molecules/loader/Loader'
import { HiOutlineUpload } from 'react-icons/hi'
import { ToastType, toast } from '@proofzero/design-system/src/atoms/toast'

const EditProfileModal: React.FC<{
isOpen: boolean
Expand All @@ -26,6 +27,16 @@ const EditProfileModal: React.FC<{
useEffect(() => {
if (fetcher.state === 'idle' && fetcher.type === 'done') {
setIsOpen(false)

if (!fetcher.data?.error) {
toast(ToastType.Success, {
message: fetcher.data.message,
})
} else if (fetcher.data?.error) {
toast(ToastType.Error, {
message: fetcher.data.message,
})
}
}
}, [fetcher])

Expand Down
24 changes: 17 additions & 7 deletions apps/passport/app/routes/settings/profile/patch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ActionFunction } from '@remix-run/cloudflare'
import { json, type ActionFunction } from '@remix-run/cloudflare'
import { getCoreClient } from '~/platform.server'
import { getValidatedSessionContext } from '~/session.server'
import { getRollupReqFunctionErrorWrapper } from '@proofzero/utils/errors'
Expand All @@ -16,12 +16,22 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
const name = formData.get('name') as string | undefined
const picture = formData.get('picture') as string | undefined

const coreClient = getCoreClient({ context, jwt })
await coreClient.identity.patchProfileFields.mutate({
displayName: name,
pictureURL: picture,
})
try {
const coreClient = getCoreClient({ context, jwt })
await coreClient.identity.patchProfileFields.mutate({
displayName: name,
pictureURL: picture,
})
} catch (ex) {
return json({
error: true,
message: 'Profile update unsuccessful',
})
}

return null
return json({
error: false,
message: 'Profile updated successfully',
})
}
)
18 changes: 14 additions & 4 deletions apps/passport/app/routes/settings/profile/reset.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ActionFunction } from '@remix-run/cloudflare'
import { json, type ActionFunction } from '@remix-run/cloudflare'
import { getCoreClient } from '~/platform.server'
import { getValidatedSessionContext } from '~/session.server'
import { getRollupReqFunctionErrorWrapper } from '@proofzero/utils/errors'
Expand All @@ -12,9 +12,19 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
context.traceSpan
)

const coreClient = getCoreClient({ context, jwt })
await coreClient.identity.resetProfileFields.mutate()
try {
const coreClient = getCoreClient({ context, jwt })
await coreClient.identity.resetProfileFields.mutate()
} catch (ex) {
return json({
error: true,
message: 'Profile update unsuccessful',
})
}

return null
return json({
error: false,
message: 'Profile updated successfully',
})
}
)

0 comments on commit e995215

Please sign in to comment.