Skip to content

Commit

Permalink
Merge branch 'master' into developer-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Pav0l committed Sep 20, 2019
2 parents 48bdd4a + 4ced9ec commit 196db6d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
18 changes: 16 additions & 2 deletions src/components/pages/AddStaff/AddStaff.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function AddStaff() {
const [state, updateState] = useState({
username: '',
password: '',
confirmPassword: '',
isAdmin: false,
createAccount: false,
errors: {}
Expand All @@ -36,7 +37,8 @@ function AddStaff() {

const credential = {
username: state.username,
password: state.password
password: state.password,
confirmPassword: state.confirmPassword
};

const { errors, isValid } = await validateAddStaffForm(credential);
Expand All @@ -49,6 +51,16 @@ function AddStaff() {
}));
}

if (state.password !== state.confirmPassword) {
return updateState(prevState => ({
...prevState,
createAccount: false,
password: '',
confirmPassword: '',
errors: [{ password: 'Passwords do not match' }]
}));
}

const response = await registrationHandler({
username: state.username,
password: state.password,
Expand All @@ -69,7 +81,8 @@ function AddStaff() {

return updateState(prevState => ({
...prevState,
createAccount: false
createAccount: false,
errors: {}
}));
} else if (response === 'New user created') {
toast.success('New user created');
Expand All @@ -78,6 +91,7 @@ function AddStaff() {
...prevState,
username: '',
password: '',
confirmPassword: '',
isAdmin: false,
createAccount: false
}));
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/AddStaff/AddStaff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ it('renders without crashing', () => {
expect(usernameField).toBeInTheDocument();
const passwordField = getByTestId('password-field');
expect(passwordField).toBeInTheDocument();
const confirmPasswordField = getByTestId('confirm-password-field');
expect(confirmPasswordField).toBeInTheDocument();
const adminCheckbox = getByTestId('admin-checkbox');
expect(adminCheckbox).toBeInTheDocument();
});
16 changes: 14 additions & 2 deletions src/components/pages/AddStaff/AddStaffForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ const AddStaff = props => {
data-testid="password-field"
/>
</Form.Field>
<Form.Field>
<label htmlFor="confirmPassword">Confirm Password</label>
<Form.Input
fluid
id="confirmPassword"
name="confirmPassword"
type="password"
value={state.confirmPassword}
onChange={handleChange}
data-testid="confirm-password-field"
/>
</Form.Field>
<Form.Field>
<Checkbox
label="Check this box to make this user Admin"
Expand All @@ -88,8 +100,8 @@ const AddStaff = props => {
content="Loading..."
/>
) : (
<Button color="teal" fluid content="Add Staff" />
)}
<Button color="teal" fluid content="Add Staff" />
)}
</Segment>
</Form>
</Grid.Column>
Expand Down
6 changes: 6 additions & 0 deletions src/components/pages/AddStaff/AddStaffValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const addStaffSchema = yup.object().shape({
.trim()
.required(),
password: yup
.string()
.min(6)
.max(40)
.required(),

confirmPassword: yup
.string()
.min(6)
.max(40)
Expand Down
12 changes: 9 additions & 3 deletions src/components/pages/EditCollection/EditCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import styled from 'styled-components';
import uuid from 'uuid';
import PropTypes from 'prop-types';
import moment from 'moment';
import { toast } from 'react-toastify';
import {
getChangeRequestById,
approveChangeRequest,
rejectChangeRequest
} from '../../../utils/handlers/changeRequestHandler';
import { toast } from 'react-toastify';

const Div = styled.div`
strike {
Expand Down Expand Up @@ -60,8 +60,14 @@ const EditCollection = ({ match, history, appStateShouldUpdate }) => {
};
});
})
.catch(err => toast.error(err.message));
}, [match]);
.catch(() => {
toast.error(
'Network Error when retrieving change request. Redirecting to Dashboard'
);
// If no request is found with that ID
history.push('/');
});
}, [match, history]);

const { data, cleanedData } = state;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/handlers/changeRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getChangeRequestById = requestId => {
}
})
.catch(error => {
return new Error(error);
throw new Error(error.response.data.message);
});
};

Expand Down

0 comments on commit 196db6d

Please sign in to comment.