-
Notifications
You must be signed in to change notification settings - Fork 7
ACC-50 Create edit profile page (first name, last name) #22
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
Draft
exuvia-dev
wants to merge
8
commits into
master
Choose a base branch
from
feat/acc-50
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce717a0
feat(profile): adds profile edit page
exuvia-dev d8cd760
Merge branch 'master' into feat/acc-50
exuvia-dev d8245ff
chore(comment): comment for ssr redirect
exuvia-dev 88c8aa2
feat(profile change): adds form for changing email
exuvia-dev 1242258
chore(merge): merge
exuvia-dev 170a4cb
fix: merge
exuvia-dev b78b072
Merge branch 'master' into feat/acc-50
exuvia-dev 76aba1d
fix: small fix (todo: understand what's going on :))
exuvia-dev 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
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,16 @@ | ||
import { useEffect } from 'react'; | ||
import { useEvent } from 'effector-react/ssr'; | ||
import { historyPush } from '../index'; | ||
|
||
/** | ||
* A component similar to 'Redirect' from 'react-router' | ||
* need to use this instead of original component, | ||
* because the one from 'react-router' does not work with ssr | ||
* */ | ||
export const EffectorSsrRedirect = ({ href }: { href: string }) => { | ||
const push = useEvent(historyPush); | ||
useEffect(() => { | ||
push(href); | ||
}, [push, href]); | ||
return null; | ||
}; |
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 { EffectorSsrRedirect } from './effector-ssr-redirect'; |
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,3 @@ | ||
export function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |
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
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,22 @@ | ||
import { sample } from 'effector-root'; | ||
import { contract } from 'lib/contract'; | ||
import * as model from './model'; | ||
import * as page from './page'; | ||
|
||
export { EmailsProfilePage } from './page'; | ||
|
||
sample({ | ||
clock: page.newEmailChanged, | ||
fn: (e) => e.target.value, | ||
target: model.changeEmail, | ||
}); | ||
contract({ | ||
page, | ||
model: { | ||
...model, | ||
formSubmitted: model.submitForm.prepend(() => undefined), | ||
$userNewEmail: model.$newEmail, | ||
passwordChanged: model.changePassword.prepend((e) => e.target.value), | ||
newEmailChanged: model.changeEmail.prepend((e) => e.target.value), | ||
}, | ||
}); |
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,81 @@ | ||
import { | ||
combine, | ||
createStore, | ||
createEffect, | ||
createEvent, | ||
restore, | ||
guard, | ||
} from 'effector-root'; | ||
import { sleep } from 'lib/sleep'; | ||
import { validateEmail } from 'lib/email'; | ||
import { EmailErrorType, RequestFailure } from './types'; | ||
|
||
const requestFx = createEffect( | ||
async (req: { email: string; password: string }) => { | ||
await sleep(2000); | ||
const isSuccess = Math.random() > 0.5; | ||
if (isSuccess) return req; | ||
|
||
throw { | ||
type: RequestFailure.required, | ||
}; | ||
}, | ||
); | ||
|
||
const changeEmail = createEvent<string>(); | ||
const $newEmail = restore(changeEmail, ''); | ||
const changePassword = createEvent<string>(); | ||
const $password = restore(changePassword, ''); | ||
|
||
const $emailError = $newEmail.map((email) => { | ||
if (!email) return EmailErrorType.required; | ||
if (!validateEmail(email)) return EmailErrorType.invalid; | ||
return null; | ||
}); | ||
const $isEmailValid = $emailError.map((error) => !error); | ||
const $isPasswordValid = $password.map(Boolean); | ||
|
||
const $isFormValid = combine( | ||
$isEmailValid, | ||
$isPasswordValid, | ||
(isEmail, isPw) => isEmail && isPw, | ||
); | ||
|
||
const $isFormPending = requestFx.pending; | ||
|
||
const $isSubmitDisabled = combine( | ||
$isFormValid, | ||
$isFormPending, | ||
(isValid, isPending) => !isValid || isPending, | ||
); | ||
|
||
const $isFormDisabled = $isFormPending.map((is) => is); | ||
|
||
const $errorType = createStore<RequestFailure | null>(null); | ||
|
||
const submitForm = createEvent(); | ||
|
||
requestFx.finally.watch((res) => { | ||
if (res.status === 'fail') console.log(res.error); | ||
if (res.status === 'done') console.log(res.result); | ||
}); | ||
|
||
guard({ | ||
clock: submitForm, | ||
filter: $isSubmitDisabled.map((is) => !is), | ||
source: { email: $newEmail, password: $password }, | ||
target: requestFx, | ||
}); | ||
|
||
export { | ||
submitForm, | ||
$newEmail, | ||
changeEmail, | ||
$password, | ||
changePassword, | ||
$emailError, | ||
$isFormDisabled, | ||
$isSubmitDisabled, | ||
$isFormPending, | ||
$errorType, | ||
}; |
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,128 @@ | ||
import React, { ChangeEvent, FormEvent } from 'react'; | ||
import styled from 'styled-components'; | ||
import { reflect } from 'effector-reflect'; | ||
import { Button, Form, Input, Title } from 'woly'; | ||
import { createEvent, createStore, StoreValue } from 'effector-root'; | ||
import { EmailErrorType, RequestFailure } from './types'; | ||
|
||
export const formSubmitted = createEvent<FormEvent>(); | ||
|
||
export const $userNewEmail = createStore(''); | ||
export const newEmailChanged = createEvent<ChangeEvent<HTMLInputElement>>(); | ||
export const $password = createStore(''); | ||
export const passwordChanged = createEvent<ChangeEvent<HTMLInputElement>>(); | ||
|
||
export const $emailError = createStore<EmailErrorType | null>(null); | ||
const $emailErrorMessage = $emailError.map((error) => { | ||
if (error === EmailErrorType.required) return 'Email is required'; | ||
if (error === EmailErrorType.invalid) return 'Email is invalid'; | ||
return null; | ||
}); | ||
const $passwordErrorMessage = $password.map((pw) => { | ||
if (!pw) return 'Password is required'; | ||
return null; | ||
}); | ||
|
||
export const $isFormDisabled = createStore(false); | ||
export const $isSubmitDisabled = createStore(false); | ||
|
||
export const $isFormPending = createStore(false); | ||
const $submitText = $isFormPending.map((is) => (is ? 'Sending...' : 'Change')); | ||
|
||
export const $errorType = createStore<RequestFailure | null>(null); | ||
const $errorText = $errorType.map((errorType) => { | ||
if (!errorType) return null; | ||
return 'AAAA'; | ||
}); | ||
|
||
export const EmailsProfilePage = () => { | ||
return ( | ||
<FormWrapper> | ||
<EmailForm> | ||
<Title level={1}>Change email form</Title> | ||
<Title level={2}>Email</Title> | ||
<Email placeholder="your new email" /> | ||
<EmailError /> | ||
<Title level={2}>Password</Title> | ||
<Password placeholder="password" type="password" /> | ||
<PasswordError /> | ||
<ErrorBlock /> | ||
<Submit type="submit" /> | ||
</EmailForm> | ||
</FormWrapper> | ||
); | ||
}; | ||
|
||
const Email = reflect({ | ||
view: Input, | ||
bind: { | ||
value: $userNewEmail, | ||
onChange: newEmailChanged, | ||
disabled: $isFormDisabled, | ||
}, | ||
}); | ||
const Password = reflect({ | ||
view: Input, | ||
bind: { | ||
value: $password, | ||
onChange: passwordChanged, | ||
disabled: $isFormDisabled, | ||
}, | ||
}); | ||
const EmailError = reflect({ | ||
view: ({ error }: { error: StoreValue<typeof $emailErrorMessage> }) => { | ||
if (error) return <ErrorTitle>{error}</ErrorTitle>; | ||
return null; | ||
}, | ||
bind: { | ||
error: $emailErrorMessage, | ||
}, | ||
}); | ||
const PasswordError = reflect({ | ||
view: ({ error }: { error: StoreValue<typeof $passwordErrorMessage> }) => { | ||
if (error) return <ErrorTitle>{error}</ErrorTitle>; | ||
return null; | ||
}, | ||
bind: { | ||
error: $passwordErrorMessage, | ||
}, | ||
}); | ||
|
||
const ErrorBlock = reflect({ | ||
view: ({ failure }: { failure: string | null }) => { | ||
if (failure) { | ||
return <Fail>{failure}</Fail>; | ||
} | ||
return null; | ||
}, | ||
bind: { | ||
failure: $errorText, | ||
}, | ||
}); | ||
|
||
const Submit = reflect({ | ||
view: Button, | ||
bind: { | ||
disable: $isSubmitDisabled, | ||
text: $submitText, | ||
}, | ||
}); | ||
|
||
const EmailForm = reflect({ | ||
view: Form, | ||
bind: { | ||
onSubmit: formSubmitted, | ||
}, | ||
}); | ||
|
||
const Fail = styled.div` | ||
font-size: 1.3rem; | ||
margin-bottom: 1rem; | ||
`; | ||
const ErrorTitle = styled.span` | ||
color: red; | ||
display: block; | ||
`; | ||
const FormWrapper = styled.div` | ||
padding: 3rem; | ||
`; |
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,7 @@ | ||
export enum EmailErrorType { | ||
required = 'required', | ||
invalid = 'invalid', | ||
} | ||
export enum RequestFailure { | ||
required = 'required', | ||
} |
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,7 @@ | ||
import { contract } from 'lib/contract'; | ||
import * as page from './page'; | ||
import * as model from './model'; | ||
|
||
export { SettingsPage } from './page'; | ||
|
||
contract({ page, model }); |
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 { createStart } from 'lib/page-routing'; | ||
import { checkAuthenticated } from '../../features/session'; | ||
|
||
export const pageStarted = createStart(); | ||
checkAuthenticated({ when: pageStarted }); |
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,25 @@ | ||
import React from 'react'; | ||
import { Route, Switch } from 'react-router-dom'; | ||
import { EffectorSsrRedirect } from 'features/navigation'; | ||
import { createStart, withStart } from 'lib/page-routing'; | ||
import { path } from '../paths'; | ||
import { SettingsProfilePage } from './profile'; | ||
import { EmailsProfilePage } from './emails'; | ||
|
||
export const pageStarted = createStart(); | ||
|
||
export const SettingsPage = withStart(pageStarted, () => { | ||
return ( | ||
<Switch> | ||
<Route exact path={path.settings.profile()}> | ||
<SettingsProfilePage /> | ||
</Route> | ||
<Route exact path={path.settings.emails()}> | ||
<EmailsProfilePage /> | ||
</Route> | ||
<Route path="*"> | ||
<EffectorSsrRedirect href={path.settings.profile()} /> | ||
</Route> | ||
</Switch> | ||
); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем?