mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 10:45:20 -04:00

* Added mock profile page * Added translations * Modularized page, added LoginProvider, started validation * Re-adding profile route after router refactoring * Added API calls for password and name change * Added user deletion modal * Refactored translations in profile-page to match new locales * Fixed merge-conflicted locales/de.json * Removed values for password fields * Fixed capitalization of LoginProvider * Fixed codestyle method declarations * Fix names of methods and started countdown * Fix countdown Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import React, { ChangeEvent, FormEvent, useState } from 'react'
|
|
import { Button, Card, Form } from 'react-bootstrap'
|
|
import { Trans, useTranslation } from 'react-i18next'
|
|
import { useSelector } from 'react-redux'
|
|
import { updateDisplayName } from '../../../../../api/user'
|
|
import { ApplicationState } from '../../../../../redux'
|
|
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
|
|
|
export const ProfileDisplayName: React.FC = () => {
|
|
const { t } = useTranslation()
|
|
const user = useSelector((state: ApplicationState) => state.user)
|
|
const [submittable, setSubmittable] = useState(false)
|
|
const [error, setError] = useState(false)
|
|
const [displayName, setDisplayName] = useState(user.name)
|
|
|
|
const regexInvalidDisplayName = /^\s*$/
|
|
|
|
const changeNameField = (event: ChangeEvent<HTMLInputElement>) => {
|
|
setSubmittable(!regexInvalidDisplayName.test(event.target.value))
|
|
setDisplayName(event.target.value)
|
|
}
|
|
|
|
const doAsyncChange = async () => {
|
|
await updateDisplayName(displayName)
|
|
await getAndSetUser()
|
|
}
|
|
|
|
const changeNameSubmit = (event: FormEvent) => {
|
|
doAsyncChange().catch(() => setError(true))
|
|
event.preventDefault()
|
|
}
|
|
|
|
return (
|
|
<Card className="bg-dark mb-4">
|
|
<Card.Body>
|
|
<Card.Title>
|
|
<Trans i18nKey="profile.userProfile"/>
|
|
</Card.Title>
|
|
<Form onSubmit={changeNameSubmit} className="text-left">
|
|
<Form.Group controlId="displayName">
|
|
<Form.Label><Trans i18nKey="profile.displayName"/></Form.Label>
|
|
<Form.Control
|
|
type="text"
|
|
size="sm"
|
|
placeholder={t('profile.displayName')}
|
|
value={displayName}
|
|
className="bg-dark text-white"
|
|
onChange={changeNameField}
|
|
isValid={submittable}
|
|
isInvalid={error}
|
|
required
|
|
/>
|
|
<Form.Text><Trans i18nKey="profile.displayNameInfo"/></Form.Text>
|
|
</Form.Group>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="primary"
|
|
disabled={!submittable}>
|
|
<Trans i18nKey="common.save"/>
|
|
</Button>
|
|
</Form>
|
|
</Card.Body>
|
|
</Card>
|
|
)
|
|
}
|