-
Notifications
You must be signed in to change notification settings - Fork 44
feat: profile page revamp #1484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
66f576d
chore: use apsara v1 in sdk
rohanchkrabrty b6b1082
feat: general page revamp
rohanchkrabrty fd07c82
feat: preferences page revamp
rohanchkrabrty 09f6f1b
feat: profile page revamp
rohanchkrabrty 38a6015
Merge branch 'main' into feat-profile-revamp
rohanchkrabrty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { ProfileView } from '@raystack/frontier/react'; | ||
|
|
||
| export default function Profile() { | ||
| return <ProfileView />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { ProfileView } from './profile-view'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .section { | ||
| padding: var(--rs-space-9) 0; | ||
| border-bottom: 1px solid var(--rs-color-border-base-primary); | ||
| } | ||
|
|
||
| .formFields { | ||
| max-width: 320px; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect } from 'react'; | ||
| import { yupResolver } from '@hookform/resolvers/yup'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import * as yup from 'yup'; | ||
| import { | ||
| createConnectQueryKey, | ||
| useMutation | ||
| } from '@connectrpc/connect-query'; | ||
| import { FrontierServiceQueries } from '@raystack/proton/frontier'; | ||
| import { useQueryClient } from '@tanstack/react-query'; | ||
| import { | ||
| Button, | ||
| Flex, | ||
| InputField, | ||
| Skeleton, | ||
| toastManager | ||
| } from '@raystack/apsara-v1'; | ||
| import { useFrontier } from '../../contexts/FrontierContext'; | ||
| import { ViewContainer } from '../../components/view-container'; | ||
| import { ViewHeader } from '../../components/view-header'; | ||
| import { ImageUpload } from '../../components/image-upload'; | ||
| import styles from './profile-view.module.css'; | ||
|
|
||
| const profileSchema = yup | ||
| .object({ | ||
| avatar: yup.string().optional(), | ||
| title: yup | ||
| .string() | ||
| .required('Name is required') | ||
| .min(2, 'Name must be at least 2 characters') | ||
| .matches( | ||
| /^[\p{L} .'-]+$/u, | ||
| 'Name can only contain letters, spaces, periods, hyphens, and apostrophes' | ||
| ) | ||
| .matches(/^\p{L}/u, 'Name must start with a letter') | ||
| .matches( | ||
| /^\p{L}[\p{L} .'-]*\p{L}$|^\p{L}$/u, | ||
| 'Name must end with a letter' | ||
| ) | ||
| .matches(/^(?!.* {2}).*$/, 'Name cannot have consecutive spaces') | ||
| .matches(/^(?!.* [^\p{L}]).*$/u, 'Spaces must be followed by a letter') | ||
| .matches(/^(?!.*-[^\p{L}]).*$/u, 'Hyphens must be followed by a letter') | ||
| .matches( | ||
| /^(?!.*'[^\p{L}]).*$/u, | ||
| 'Apostrophes must be followed by a letter' | ||
| ), | ||
| email: yup.string().email().required() | ||
| }) | ||
| .required(); | ||
|
|
||
| type FormData = yup.InferType<typeof profileSchema>; | ||
|
|
||
| export function ProfileView() { | ||
| const { user, isUserLoading: isLoading } = useFrontier(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const { mutateAsync: updateCurrentUser } = useMutation( | ||
| FrontierServiceQueries.updateCurrentUser, | ||
| { | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ | ||
| queryKey: createConnectQueryKey({ | ||
| schema: FrontierServiceQueries.getCurrentUser, | ||
| cardinality: 'finite' | ||
| }) | ||
| }); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| const { | ||
| reset, | ||
| register, | ||
| handleSubmit, | ||
| watch, | ||
| setValue, | ||
| formState: { errors, isSubmitting, isDirty } | ||
| } = useForm({ | ||
| resolver: yupResolver(profileSchema) | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| reset(user, { keepDirtyValues: true }); | ||
| }, [user, reset]); | ||
|
|
||
| async function onSubmit(data: FormData) { | ||
| try { | ||
| if (!user?.id) return; | ||
| await updateCurrentUser({ body: data }); | ||
| toastManager.add({ title: 'Updated user', type: 'success' }); | ||
| } catch (err: unknown) { | ||
| toastManager.add({ | ||
| title: 'Something went wrong', | ||
| description: err instanceof Error ? err.message : 'Failed to update', | ||
| type: 'error' | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <ViewContainer> | ||
| <ViewHeader | ||
| title="Profile" | ||
| description="Manage your profile information and settings." | ||
| /> | ||
|
|
||
| <form onSubmit={handleSubmit(onSubmit)}> | ||
| <Flex direction="column"> | ||
| {/* Avatar section */} | ||
| <Flex direction="column" gap={5} className={styles.section}> | ||
| {isLoading ? ( | ||
| <Flex direction="column" gap={5}> | ||
| <Skeleton width="72px" height="72px" /> | ||
| <Skeleton height="20px" width="50%" /> | ||
| </Flex> | ||
| ) : ( | ||
| <ImageUpload | ||
| value={watch('avatar')} | ||
| onChange={(value: string) => | ||
| setValue('avatar', value, { shouldDirty: true }) | ||
| } | ||
| description="Pick a profile picture for your avatar. Max size: 5 Mb" | ||
| initials={user?.title?.[0]} | ||
| data-test-id="frontier-sdk-profile-avatar-upload" | ||
| /> | ||
| )} | ||
| </Flex> | ||
|
|
||
| {/* Form section */} | ||
| <Flex direction="column" gap={7} className={styles.section}> | ||
| <Flex direction="column" gap={9} className={styles.formFields}> | ||
| {isLoading ? ( | ||
| <> | ||
| <Skeleton height="58px" /> | ||
| <Skeleton height="58px" /> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <InputField | ||
| label="Full name" | ||
| size="large" | ||
| error={errors.title && String(errors.title?.message)} | ||
| defaultValue={user?.title || ''} | ||
| placeholder="Provide full name" | ||
| {...register('title')} | ||
| disabled={isLoading} | ||
| /> | ||
| <InputField | ||
| label="Email address" | ||
| size="large" | ||
| error={errors.email && String(errors.email?.message)} | ||
| value={user?.email || ''} | ||
| type="email" | ||
| placeholder="Provide email address" | ||
| {...register('email')} | ||
| readOnly | ||
| disabled | ||
| /> | ||
| </> | ||
| )} | ||
| </Flex> | ||
|
|
||
| {isLoading ? ( | ||
| <Skeleton height="32px" width="64px" /> | ||
| ) : ( | ||
| <Button | ||
| type="submit" | ||
| variant="solid" | ||
| color="accent" | ||
| disabled={isLoading || isSubmitting || !isDirty} | ||
| loading={isSubmitting} | ||
| loaderText="Updating..." | ||
| data-test-id="frontier-sdk-update-user-btn" | ||
| > | ||
| Update | ||
| </Button> | ||
| )} | ||
| </Flex> | ||
| </Flex> | ||
| </form> | ||
| </ViewContainer> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.