Skip to content
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

Feat: Add accordion for settings form #3988

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/assets/icons/chevron-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/components/assets/icons/chevron-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/pages/UserSettings/SettingsPageAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const SettingsPageAccount = observer(() => {
</Flex>

<PatreonIntegration user={userStore.activeUser} />
<ChangeEmailForm />
<ChangePasswordForm />
<ChangeEmailForm />

<Text variant="body">
{title}
Expand Down
57 changes: 30 additions & 27 deletions src/pages/UserSettings/content/sections/ChangeEmail.form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { Field, Form } from 'react-final-form'
import { Button, FieldInput, Icon } from 'oa-components'
import { Button, ButtonIcon, FieldInput } from 'oa-components'
import { PasswordField } from 'src/common/Form/PasswordField'
import { useCommonStores } from 'src/common/hooks/useCommonStores'
import { FormFieldWrapper } from 'src/pages/Howto/Content/Common'
Expand All @@ -22,7 +22,7 @@ export const ChangeEmailForm = () => {

const { userStore } = useCommonStores().stores
const formId = 'changeEmail'
const glyph = isExpanded ? 'arrow-full-up' : 'arrow-full-down'
const dropdownIcon = isExpanded ? 'chevron-up' : 'chevron-down'

useEffect(() => {
getUserEmail()
Expand Down Expand Up @@ -54,7 +54,33 @@ export const ChangeEmailForm = () => {
sx={{ flexDirection: 'column', gap: 2 }}
>
<UserContactError submitResults={submitResults} />

<Flex
sx={{
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<Heading as="h3" variant="small">
{headings.changeEmail}
</Heading>
<ButtonIcon
data-cy="ChangeEmail-DropdownButton"
icon={dropdownIcon}
onClick={() => setIsExpanded(!isExpanded)}
sx={{
paddingRight: 3,
paddingLeft: 2,
border: 'none',
':hover': {
backgroundColor: 'unset',
cursor: 'pointer',
},
}}
/>
</Flex>
<Text sx={{ fontSize: 1 }}>
{fields.email.title}: <strong>{currentEmail}</strong>
</Text>
{isExpanded && currentEmail && (
<Form
onSubmit={onSubmit}
Expand All @@ -67,16 +93,8 @@ export const ChangeEmailForm = () => {
return (
<Flex
data-cy="changeEmailForm"
sx={{ flexDirection: 'column', gap: 2 }}
sx={{ flexDirection: 'column', gap: 2, marginTop: 5 }}
>
<Heading as="h3" variant="small">
{headings.changeEmail}
</Heading>

<Text sx={{ fontSize: 1 }}>
{fields.email.title}: <strong>{currentEmail}</strong>
</Text>

<FormFieldWrapper
text={fields.newEmail.title}
htmlFor="newEmail"
Expand Down Expand Up @@ -125,21 +143,6 @@ export const ChangeEmailForm = () => {
}}
/>
)}

<Button
type="button"
data-cy="changeEmailButton"
onClick={() => setIsExpanded(!isExpanded)}
variant="secondary"
sx={{
alignSelf: 'flex-start',
}}
>
<Flex sx={{ gap: 2 }}>
<Text>{buttons.changeEmail}</Text>
<Icon glyph={glyph} />
</Flex>
</Button>
</Flex>
)
}
56 changes: 33 additions & 23 deletions src/pages/UserSettings/content/sections/ChangePassword.form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { Form } from 'react-final-form'
import { Button, FieldInput, Icon } from 'oa-components'
import { Button, ButtonIcon, FieldInput } from 'oa-components'
import { PasswordField } from 'src/common/Form/PasswordField'
import { useCommonStores } from 'src/common/hooks/useCommonStores'
import { FormFieldWrapper } from 'src/pages/Howto/Content/Common'
Expand All @@ -22,7 +22,7 @@ export const ChangePasswordForm = () => {

const { userStore } = useCommonStores().stores
const formId = 'changePassword'
const glyph = isExpanded ? 'arrow-full-up' : 'arrow-full-down'
const dropdownIcon = isExpanded ? 'chevron-up' : 'chevron-down'

const onSubmit = async (values: IFormValues) => {
const { oldPassword, newPassword } = values
Expand All @@ -45,7 +45,36 @@ export const ChangePasswordForm = () => {
sx={{ flexDirection: 'column', gap: 2 }}
>
<UserContactError submitResults={submitResults} />

<Flex
sx={{
alignItems: 'center',
justifyContent: 'space-between',
':hover': {
cursor: 'pointer',
},
}}
onClick={() => setIsExpanded(!isExpanded)}
>
<Heading as="h3" variant="small">
{headings.changePassword}
</Heading>
<ButtonIcon
data-cy="ChangePassword-DropdownButton"
icon={dropdownIcon}
sx={{
paddingRight: 3,
paddingLeft: 2,
border: 'none',
':hover': {
backgroundColor: 'unset',
cursor: 'pointer',
},
}}
/>
</Flex>
<Text sx={{ fontSize: 1 }}>
Here you can change your password to be a stronger one. 💪
</Text>
{isExpanded && (
<Form
onSubmit={onSubmit}
Expand All @@ -62,12 +91,8 @@ export const ChangePasswordForm = () => {
return (
<Flex
data-cy="changePasswordForm"
sx={{ flexDirection: 'column', gap: 1 }}
sx={{ flexDirection: 'column', gap: 1, marginTop: 5 }}
>
<Heading as="h3" variant="small">
{headings.changePassword}
</Heading>

<FormFieldWrapper
text={fields.oldPassword.title}
htmlFor="oldPassword"
Expand Down Expand Up @@ -130,21 +155,6 @@ export const ChangePasswordForm = () => {
}}
/>
)}

<Button
type="button"
data-cy="changePasswordButton"
onClick={() => setIsExpanded(!isExpanded)}
variant="secondary"
sx={{
alignSelf: 'flex-start',
}}
>
<Flex sx={{ gap: 2 }}>
<Text>{buttons.changePassword}</Text>
<Icon glyph={glyph} />
</Flex>
</Button>
</Flex>
)
}
Loading