Error
+There was an error
{error}
diff --git a/client/src/api/profile.js b/client/src/api/profile.js index 48246ac61..f1cbcf250 100644 --- a/client/src/api/profile.js +++ b/client/src/api/profile.js @@ -1,4 +1,4 @@ -import { request } from './util' +import { request, relog } from './util' export const privateProfile = () => { return request('GET', '/users/me') @@ -9,3 +9,21 @@ export const publicProfile = uuid => { return request('GET', '/users/' + encodeURIComponent(uuid)) .then(resp => resp.data) } + +export const deleteAccount = () => { + return request('DELETE', '/users/me') + .then(resp => { + switch (resp.kind) { + case 'goodUserDelete': + return relog() + } + }) +} + +export const updateAccount = (name, division) => { + return request('PATCH', '/users/me', { + name, + division: Number.parseInt(division) + }) + .then(resp => resp.data) +} diff --git a/client/src/api/util.js b/client/src/api/util.js index 7d87c2f04..8fc12ce38 100644 --- a/client/src/api/util.js +++ b/client/src/api/util.js @@ -1,7 +1,7 @@ import { route } from 'preact-router' import config from '../../../config/client' -const relog = () => { +export const relog = () => { localStorage.removeItem('token') route('/register') } diff --git a/client/src/pages/profile.js b/client/src/pages/profile.js index 8707e4818..dc4a30fe7 100644 --- a/client/src/pages/profile.js +++ b/client/src/pages/profile.js @@ -3,10 +3,18 @@ import config from '../../../config/client' import 'linkstate/polyfill' import withStyles from '../components/jss' -import { privateProfile, publicProfile } from '../api/profile' +import { privateProfile, publicProfile, deleteAccount, updateAccount } from '../api/profile' +import Form from '../components/form' import util from '../util' import Trophy from '../../static/icons/trophy.svg' import AddressBook from '../../static/icons/address-book.svg' +import UserCircle from '../../static/icons/user-circle.svg' + +const divisionMap = new Map() + +for (const division of Object.entries(config.divisions)) { + divisionMap.set(division[1], division[0]) +} export default withStyles({ quote: { @@ -20,6 +28,15 @@ export default withStyles({ fill: '#333' }, marginRight: '25px' + }, + form: { + '& button': { + margin: 0, + lineHeight: '20px', + padding: '10px', + float: 'right' + }, + padding: '0 !important' } }, class Profile extends Component { state = { @@ -31,13 +48,18 @@ export default withStyles({ teamToken: '', solves: [], uuid: '', - error: undefined + error: undefined, + updateName: '', + updateDivision: 0, + disabledButton: false } processGeneric ({ name, division, score, divisionPlace, solves }) { this.setState({ name: name, + updateName: name, division: division, + updateDivision: config.divisions[division], placement: util.strings.placementString(divisionPlace), score, solves: solves, @@ -87,7 +109,30 @@ export default withStyles({ } } - render ({ classes }, { name, division, placement, score, teamToken, solves, error, loaded }) { + handleUpdate = e => { + e.preventDefault() + + this.setState({ + disabledButton: true + }) + + updateAccount(this.state.updateName, this.state.updateDivision) + .then(resp => this.setState({ + name: resp.user.name, + division: divisionMap.get(Number.parseInt(resp.user.division)), + disabledButton: false + })) + } + + handleDelete = e => { + const resp = prompt('Please type your team name to confirm: ' + this.state.name) + + if (resp === this.state.name) { + deleteAccount() + } + } + + render ({ classes }, { name, division, placement, score, teamToken, solves, error, loaded, updateName, updateDivision, disabledButton }) { const priv = this.isPrivate() const hasError = error !== undefined @@ -99,7 +144,7 @@ export default withStyles({
Error
+There was an error
{error}
Share this with your teammates to use at /login!
Update Information
+Category | -Name | -Points | -
---|---|---|
{solve.category} | {solve.name} | {solve.points} |
Category | +Name | +Points | +
---|---|---|
{solve.category} | {solve.name} | {solve.points} |