Skip to content

Commit 04a111f

Browse files
Allow user to update their timezones
1 parent a66433c commit 04a111f

File tree

10 files changed

+75
-28
lines changed

10 files changed

+75
-28
lines changed

Diff for: .eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
build
3+

Diff for: Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ build:
4242
--name reconmap-web-frontend \
4343
reconmap-web-frontend build
4444

45+
.PHONY: shell
46+
shell:
47+
docker exec -it reconmap-web-frontend bash
48+
49+

Diff for: package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@testing-library/jest-dom": "^4.2.4",
77
"@testing-library/react": "^9.3.2",
88
"@testing-library/user-event": "^7.1.2",
9+
"countries-and-timezones": "^2.3.1",
910
"dayjs": "^1.8.34",
1011
"node-sass": "^4.14.1",
1112
"react": "^16.13.1",

Diff for: src/components/ui/buttons/Cancel.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react";
2+
import { IconX } from "../../icons";
3+
4+
const CancelButton = ({ onClick, children }) => <button onClick={onClick} type="cancel" className="flex">
5+
<IconX styling='mr-2'/>
6+
{children || "Cancel"}
7+
</button>
8+
9+
export default CancelButton

Diff for: src/components/ui/buttons/Create.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
2-
import { IconPlus } from "../../icons";
2+
import { IconPlus } from "../../icons";
33

4-
const CreateButton = ({onClick, children}) => <button onClick={onClick} >
5-
<IconPlus styling='mr-2'/>
6-
{children || "Create"}
7-
</button>
4+
const CreateButton = ({ onClick, children }) => <button onClick={onClick} >
5+
<IconPlus styling='mr-2' />
6+
{children || "Create"}
7+
</button>
88

99
export default CreateButton

Diff for: src/components/ui/buttons/Delete.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from "react";
22
import { IconX } from "../../icons";
33

44
const DeleteButton = (props) => <button onClick={props.onClick} type="delete">
5-
<IconX styling='mr-2'/>
6-
{props.children || "Delete"}
5+
<IconX styling='mr-2' />
6+
{props.children || "Delete"}
77
</button>
88

99
export default DeleteButton

Diff for: src/components/user/Preferences.js

+38-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
1-
import React from 'react'
1+
import React, { useState } from 'react'
22
import useSetTitle from '../../hooks/useSetTitle'
3-
import { IconSave, IconX } from './../icons'
3+
import { IconSave } from './../icons'
44
import Breadcrumb from '../ui/Breadcrumb'
5+
import CancelButton from '../ui/buttons/Cancel'
6+
import { getAllTimezones } from 'countries-and-timezones';
7+
import secureApiFetch from '../../services/api';
58

6-
const UserPreferences = ({history}) => {
9+
const UserPreferences = ({ history }) => {
710
useSetTitle('Preferences')
11+
const timezones = getAllTimezones();
12+
const timezoneKeys = Object.keys(timezones).sort();
13+
const [timezone, setTimezone] = useState(null);
14+
const user = JSON.parse(localStorage.getItem('user'));
15+
16+
const handleChange = (e) => {
17+
setTimezone(e.target.value);
18+
}
19+
20+
const handleSubmit = () => {
21+
secureApiFetch(`/users/${user.id}`, {
22+
method: 'PATCH',
23+
body: JSON.stringify({ timezone: timezone })
24+
})
25+
.then(() => {
26+
user.timezone = timezone;
27+
localStorage.setItem('user', JSON.stringify(user));
28+
history.push('/');
29+
})
30+
.catch(e => console.log(e))
31+
}
32+
833
return (
934
<>
10-
<Breadcrumb path={history.location.pathname}/>
35+
<Breadcrumb path={history.location.pathname} />
1136
<h1>Preferences</h1>
12-
<form onSubmit={e=>e.preventDefault()}>
13-
<label>Language</label>
14-
<select>
15-
<option>English</option>
16-
<option>Spanish</option>
17-
</select>
18-
19-
<label>Timezone</label>
20-
<select>
21-
<option>UTC-4</option>
22-
<option>UTC</option>
23-
</select>
37+
<form onSubmit={e => e.preventDefault()}>
38+
<label>Timezone</label>
39+
<select onChange={handleChange} defaultValue={user.timezone}>
40+
{timezoneKeys.map((key) =>
41+
<option value={timezones[key].name}>{timezones[key].name}</option>
42+
)}
43+
</select>
2444

25-
<button className='flex '><IconSave styling='mr-2'/> Save</button>
26-
<button className='flex ' type='cancel'><IconX styling='mr-2'/> Cancel</button>
45+
<button className='flex ' onClick={handleSubmit}><IconSave styling='mr-2' /> Save</button>
46+
<CancelButton onClick={() => { history.push("/") }} />
2747
</form>
2848
</>
2949
)

Diff for: src/components/user/Profile.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ const UserProfile = ({ match, history }) => {
2020
{user && <UserAvatar email={user.email} size={48}/>}
2121
{user ? <div className=' flex flex-col flex-1 ml-5'>
2222
<h1>{user.name}</h1>
23-
<article className='text-gray-600'>
24-
User since {user.insert_ts}
25-
</article>
23+
<dl className='text-gray-600'>
24+
<dt>User since</dt>
25+
<dd>{user.insert_ts}</dd>
26+
27+
<dt>Timezone</dt>
28+
<dd>{user.timezone}</dd>
29+
</dl>
2630
<div className='flex flex-row gap-4 my-2 font-semibold text-sm'>
2731
<UserRoleBadge role={user.role} />
2832
</div>

Diff for: src/contexts/AuthContext.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AuthProvider extends Component {
3535
localStorage.setItem("accessToken", data.access_token);
3636
localStorage.setItem('isAuth', true);
3737
localStorage.setItem('user.id', data.id);
38+
localStorage.setItem('user', JSON.stringify(data));
3839
this.setState({ isAuth: true });
3940
onOk();
4041
})

0 commit comments

Comments
 (0)