2020-01-12 08:16:09 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2022-07-13 03:14:23 +00:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2020-07-18 06:12:10 +00:00
|
|
|
import * as loadImage from 'blueimp-load-image';
|
2020-07-17 04:48:40 +00:00
|
|
|
import ReactCrop from 'react-image-crop';
|
|
|
|
import 'react-image-crop/dist/ReactCrop.css';
|
2020-01-12 08:16:09 +00:00
|
|
|
import './light.css';
|
2022-07-13 03:14:23 +00:00
|
|
|
import { Button, Container, Form, Grid, Header, Message, Segment } from 'semantic-ui-react';
|
|
|
|
import { requester, randomString } from './utils.js';
|
2020-01-12 08:16:09 +00:00
|
|
|
|
2020-01-23 03:32:54 +00:00
|
|
|
function LogoutEverywhere(props) {
|
|
|
|
const { token } = props;
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [yousure, setYousure] = useState(false);
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
if (yousure) {
|
2020-02-04 07:18:29 +00:00
|
|
|
if (loading) return;
|
2020-01-23 03:32:54 +00:00
|
|
|
setLoading(true);
|
|
|
|
requester('/rest-auth/logout/', 'POST', token, {})
|
|
|
|
.then(res => {
|
|
|
|
setYousure(false);
|
|
|
|
history.push('/');
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setYousure(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Header size='medium'>Log Out from Everywhere</Header>
|
|
|
|
|
|
|
|
<p>Use this to log out from all sessions on all computers.</p>
|
|
|
|
|
|
|
|
{error && <p>Error, something went wrong.</p>}
|
|
|
|
|
|
|
|
<Button onClick={handleClick} loading={loading}>
|
|
|
|
{yousure ? 'You Sure?' : 'Log Out Everywhere'}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-12 08:54:32 +00:00
|
|
|
function ChangePasswordForm(props) {
|
2020-01-18 01:27:56 +00:00
|
|
|
const { token } = props;
|
2020-01-12 08:54:32 +00:00
|
|
|
const [input, setInput] = useState({});
|
|
|
|
const [error, setError] = useState({});
|
2021-09-18 20:45:12 +00:00
|
|
|
const [progress, setProgress] = useState([]);
|
2020-01-12 08:54:32 +00:00
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
|
|
|
|
const handleChange = (e) => handleValues(e, e.currentTarget);
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
2020-02-04 07:18:29 +00:00
|
|
|
if (loading) return;
|
2020-01-12 08:54:32 +00:00
|
|
|
setLoading(true);
|
2021-09-18 20:45:12 +00:00
|
|
|
|
|
|
|
const request_id = randomString();
|
|
|
|
const getStatus = () => {
|
|
|
|
requester('/stats/progress/?request_id='+request_id, 'GET')
|
|
|
|
.then(res => {
|
|
|
|
setProgress(res);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const interval = setInterval(getStatus, 500);
|
|
|
|
|
|
|
|
const data = { ...input, request_id: request_id };
|
|
|
|
requester('/password/change/', 'POST', token, data)
|
2020-01-12 08:54:32 +00:00
|
|
|
.then(res => {
|
2021-09-18 20:45:12 +00:00
|
|
|
clearInterval(interval);
|
2020-01-12 08:54:32 +00:00
|
|
|
setError({});
|
|
|
|
history.push('/');
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2021-09-18 20:45:12 +00:00
|
|
|
clearInterval(interval);
|
2020-01-12 08:54:32 +00:00
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeProps = (name) => ({
|
|
|
|
name: name,
|
|
|
|
onChange: handleChange,
|
2020-01-14 00:52:15 +00:00
|
|
|
value: input[name] || '',
|
2020-01-12 08:54:32 +00:00
|
|
|
error: error[name],
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<Header size='medium'>Change Password</Header>
|
|
|
|
|
|
|
|
<Form.Input
|
|
|
|
label='Old Password'
|
|
|
|
type='password'
|
2020-01-14 00:52:15 +00:00
|
|
|
required
|
2020-01-12 08:54:32 +00:00
|
|
|
{...makeProps('old_password')}
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
label='New Password'
|
|
|
|
type='password'
|
2020-01-14 00:52:15 +00:00
|
|
|
required
|
2020-01-12 08:54:32 +00:00
|
|
|
{...makeProps('new_password1')}
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
label='Confirm Password'
|
|
|
|
type='password'
|
2020-01-14 00:52:15 +00:00
|
|
|
required
|
2020-01-12 08:54:32 +00:00
|
|
|
{...makeProps('new_password2')}
|
|
|
|
/>
|
|
|
|
|
2021-09-18 20:45:12 +00:00
|
|
|
<p>
|
|
|
|
{progress.map(x => <>{x}<br /></>)}
|
|
|
|
</p>
|
|
|
|
|
2020-01-12 08:54:32 +00:00
|
|
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
|
|
|
Submit
|
|
|
|
</Form.Button>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-17 04:48:40 +00:00
|
|
|
|
|
|
|
export function ImageCrop(props) {
|
|
|
|
const { file, crop, setCrop } = props;
|
|
|
|
const [src, setSrc] = useState(false);
|
2020-07-18 06:12:10 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setSrc(false);
|
|
|
|
setCrop({ unit: '%', height: 100, aspect: 3/4 });
|
|
|
|
loadImage(
|
|
|
|
file,
|
|
|
|
img => {
|
|
|
|
setSrc(img.toDataURL());
|
|
|
|
},
|
|
|
|
{
|
|
|
|
meta: true,
|
|
|
|
orientation: true,
|
|
|
|
canvas: true,
|
|
|
|
maxWidth: 300,
|
|
|
|
maxHeight: 300,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}, [file]);
|
|
|
|
|
2020-07-17 04:48:40 +00:00
|
|
|
return (
|
2020-07-18 06:12:10 +00:00
|
|
|
src ?
|
|
|
|
<ReactCrop
|
|
|
|
src={src}
|
|
|
|
crop={crop}
|
|
|
|
locked
|
|
|
|
onChange={(crop, percentCrop) => setCrop(percentCrop)}
|
|
|
|
/>
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
2020-07-17 04:48:40 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-13 03:18:41 +00:00
|
|
|
export function AccountForm(props) {
|
2020-01-18 01:27:56 +00:00
|
|
|
const { token, user, refreshUser } = props;
|
|
|
|
const member = user.member;
|
2020-01-13 08:01:42 +00:00
|
|
|
const [input, setInput] = useState({ ...member, set_details: true });
|
2020-01-12 08:16:09 +00:00
|
|
|
const [error, setError] = useState({});
|
|
|
|
const [loading, setLoading] = useState(false);
|
2020-07-18 06:12:10 +00:00
|
|
|
const [crop, setCrop] = useState(false);
|
2020-01-12 08:16:09 +00:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
|
|
|
|
const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] });
|
|
|
|
const handleChange = (e) => handleValues(e, e.currentTarget);
|
2020-01-13 03:18:41 +00:00
|
|
|
const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked });
|
2020-01-12 08:16:09 +00:00
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
2020-02-04 07:18:29 +00:00
|
|
|
if (loading) return;
|
2020-01-12 08:16:09 +00:00
|
|
|
setLoading(true);
|
2020-07-17 04:48:40 +00:00
|
|
|
const data = { ...input, email: input.email.toLowerCase(), crop: JSON.stringify(crop) };
|
2020-02-14 07:31:22 +00:00
|
|
|
requester('/members/' + member.id + '/', 'PATCH', token, data)
|
2020-01-12 08:16:09 +00:00
|
|
|
.then(res => {
|
|
|
|
setError({});
|
2020-01-18 01:27:56 +00:00
|
|
|
refreshUser();
|
2020-01-12 08:16:09 +00:00
|
|
|
history.push('/');
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeProps = (name) => ({
|
|
|
|
name: name,
|
|
|
|
onChange: handleChange,
|
2020-01-13 08:01:42 +00:00
|
|
|
value: input[name] || '',
|
2020-01-12 08:16:09 +00:00
|
|
|
error: error[name],
|
2020-01-15 00:12:50 +00:00
|
|
|
...(input[name] ? {} : {icon: 'edit'}),
|
2020-01-12 08:16:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<Header size='medium'>Member Details</Header>
|
|
|
|
|
2022-01-19 23:58:19 +00:00
|
|
|
<div className='field'>
|
2022-08-25 02:16:28 +00:00
|
|
|
<label>Spaceport Username</label>
|
2022-01-19 23:58:19 +00:00
|
|
|
<p>{user.username}</p>
|
|
|
|
</div>
|
|
|
|
|
2020-01-12 08:16:09 +00:00
|
|
|
<Form.Input
|
2020-01-13 08:01:42 +00:00
|
|
|
label='Preferred First Name'
|
2022-01-19 23:58:19 +00:00
|
|
|
autoComplete='off'
|
2020-01-13 04:58:23 +00:00
|
|
|
required
|
2020-01-13 08:01:42 +00:00
|
|
|
{...makeProps('preferred_name')}
|
2020-01-12 08:16:09 +00:00
|
|
|
/>
|
|
|
|
|
2020-01-13 03:18:41 +00:00
|
|
|
<Form.Input
|
|
|
|
label='Email Address'
|
2022-01-19 23:58:19 +00:00
|
|
|
autoComplete='off'
|
2020-01-13 04:58:23 +00:00
|
|
|
required
|
2020-01-13 03:18:41 +00:00
|
|
|
{...makeProps('email')}
|
|
|
|
/>
|
|
|
|
|
2020-01-12 08:16:09 +00:00
|
|
|
<Form.Input
|
|
|
|
label='Phone Number (999) 555-1234'
|
2022-01-19 23:58:19 +00:00
|
|
|
autoComplete='off'
|
2020-01-13 04:58:23 +00:00
|
|
|
required
|
2020-01-12 08:16:09 +00:00
|
|
|
{...makeProps('phone')}
|
|
|
|
/>
|
2020-01-13 03:18:41 +00:00
|
|
|
|
2020-01-12 08:16:09 +00:00
|
|
|
<Form.Input
|
|
|
|
label='Emergency Contact Name'
|
2022-01-19 23:58:19 +00:00
|
|
|
autoComplete='off'
|
2020-01-12 08:16:09 +00:00
|
|
|
{...makeProps('emergency_contact_name')}
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
label='Emergency Contact Phone'
|
2022-01-19 23:58:19 +00:00
|
|
|
autoComplete='off'
|
2020-01-12 08:16:09 +00:00
|
|
|
{...makeProps('emergency_contact_phone')}
|
|
|
|
/>
|
|
|
|
|
2022-04-28 21:11:56 +00:00
|
|
|
{member.mediawiki_username && <div className='field'>
|
|
|
|
<label>Custom Wiki Username</label>
|
|
|
|
<p>{member.mediawiki_username}</p>
|
|
|
|
</div>}
|
|
|
|
|
2021-10-02 04:44:33 +00:00
|
|
|
{member.discourse_username && <Form.Input
|
2022-04-28 21:11:56 +00:00
|
|
|
label='Custom Forum Username'
|
2022-01-19 23:58:19 +00:00
|
|
|
autoComplete='off'
|
2021-10-02 04:44:33 +00:00
|
|
|
{...makeProps('discourse_username')}
|
|
|
|
/>}
|
|
|
|
|
2022-03-14 04:41:37 +00:00
|
|
|
{member.discourse_username && member.discourse_username !== input.discourse_username &&
|
|
|
|
<Message info>
|
|
|
|
<Message.Header>Make sure you remember</Message.Header>
|
|
|
|
<p>You'll use this to log into the Protospace Forum (Spacebar).</p>
|
|
|
|
</Message>
|
|
|
|
}
|
|
|
|
|
2021-11-12 04:16:19 +00:00
|
|
|
<Form.Field>
|
|
|
|
<label>Participate in "Last Scanned" member list?</label>
|
2021-11-28 21:43:24 +00:00
|
|
|
<Form.Checkbox
|
2021-11-12 04:16:19 +00:00
|
|
|
label='Yes, show me'
|
|
|
|
name='allow_last_scanned'
|
|
|
|
onChange={handleCheck}
|
|
|
|
checked={input.allow_last_scanned}
|
2021-11-28 21:43:24 +00:00
|
|
|
error={error.allow_last_scanned ?
|
|
|
|
{ content: error.allow_last_scanned, pointing: 'left' }
|
|
|
|
:
|
|
|
|
false
|
|
|
|
}
|
2021-11-12 04:16:19 +00:00
|
|
|
/>
|
|
|
|
</Form.Field>
|
|
|
|
|
2020-01-12 08:16:09 +00:00
|
|
|
<Form.Input
|
|
|
|
label='Member Photo'
|
|
|
|
name='photo'
|
|
|
|
type='file'
|
|
|
|
accept='image/*'
|
|
|
|
onChange={handleUpload}
|
|
|
|
/>
|
|
|
|
|
2020-07-17 04:48:40 +00:00
|
|
|
{input.photo &&
|
|
|
|
<>
|
|
|
|
<ImageCrop file={input.photo} crop={crop} setCrop={setCrop} />
|
2020-07-18 06:12:10 +00:00
|
|
|
{crop && crop.width === crop.height ?
|
|
|
|
<p>It's the perfect size!</p>
|
|
|
|
:
|
|
|
|
<p>Move the box above to crop your image.</p>
|
|
|
|
}
|
2020-07-17 04:48:40 +00:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
|
2020-01-12 08:16:09 +00:00
|
|
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
|
|
|
Submit
|
|
|
|
</Form.Button>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-01 03:25:27 +00:00
|
|
|
export function BioNotesForm(props) {
|
|
|
|
const { token, user, refreshUser } = props;
|
|
|
|
const member = user.member;
|
|
|
|
const [input, setInput] = useState({ ...member, set_details: true });
|
|
|
|
const [error, setError] = useState({});
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
|
|
|
|
const handleChange = (e) => handleValues(e, e.currentTarget);
|
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
|
|
|
if (loading) return;
|
|
|
|
setLoading(true);
|
|
|
|
requester('/members/' + member.id + '/', 'PATCH', token, input)
|
|
|
|
.then(res => {
|
|
|
|
setError({});
|
|
|
|
refreshUser();
|
|
|
|
history.push('/');
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeProps = (name) => ({
|
|
|
|
name: name,
|
|
|
|
onChange: handleChange,
|
|
|
|
value: input[name] || '',
|
|
|
|
error: error[name],
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<Header size='medium'>Bio / Notes</Header>
|
|
|
|
|
|
|
|
<Form.TextArea
|
|
|
|
label={'Public Bio' + (input.public_bio && input.public_bio.length > 400 ? ' — ' + input.public_bio.length + ' / 512' : '')}
|
|
|
|
{...makeProps('public_bio')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<p>Bio shared with members. Example: contact info, allergies, hobbies, etc.</p>
|
|
|
|
|
|
|
|
<Form.TextArea
|
|
|
|
label={'Private Notes' + (input.private_notes && input.private_notes.length > 400 ? ' — ' + input.private_notes.length + ' / 512' : '')}
|
|
|
|
{...makeProps('private_notes')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<p>Notes visible only to directors and admins.</p>
|
|
|
|
|
|
|
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
|
|
|
Submit
|
|
|
|
</Form.Button>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-12 08:16:09 +00:00
|
|
|
export function Account(props) {
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<Header size='large'>Account Settings</Header>
|
2020-01-12 08:54:32 +00:00
|
|
|
<Grid stackable columns={2}>
|
|
|
|
<Grid.Column>
|
|
|
|
<Segment padded><AccountForm {...props} /></Segment>
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column>
|
2020-05-01 03:25:27 +00:00
|
|
|
<Segment padded><BioNotesForm {...props} /></Segment>
|
2020-01-12 08:54:32 +00:00
|
|
|
<Segment padded><ChangePasswordForm {...props} /></Segment>
|
2020-01-23 03:32:54 +00:00
|
|
|
<Segment padded><LogoutEverywhere {...props} /></Segment>
|
2020-01-12 08:54:32 +00:00
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
2020-01-12 08:16:09 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|