Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact page fully functional. Utilizes Material UI design components and inherits styles from theme #1330

Merged
merged 38 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f3c8cc9
added sendContactData function and its entry into rootSaga in /client…
edwinjue Aug 23, 2022
2f6f6d2
refactored /client/components/main/ContactForm.jsx from class to func…
edwinjue Aug 23, 2022
025e3f7
added boilerplate scss files from v1 into client/styles for ContactFo…
edwinjue Aug 24, 2022
12782ae
moved all contact files under client/components/contact, added Button…
edwinjue Aug 25, 2022
43db4cf
initial refactor of contact form utilizing material-ui
edwinjue Aug 25, 2022
5821a6c
brought back the contact image
edwinjue Aug 25, 2022
7fb307d
applied form validation control to material-ui TextField components. …
edwinjue Aug 25, 2022
f3a73eb
added Grid component to ContactIntro. contact page is looking present…
edwinjue Aug 25, 2022
216db4b
contact form now shows a confirmation message upon successful submiss…
edwinjue Aug 26, 2022
7df6c06
reconfigured ToastContainer in Contact.jsx and toast calls in Contact…
edwinjue Aug 26, 2022
dbdb492
removed some blank lines to improve readability
edwinjue Aug 26, 2022
4c28f42
turned off autocomplete for all MUI TextField components in the Conta…
edwinjue Aug 26, 2022
dca1d27
display mui CircularProgress element when submit button clicked to di…
edwinjue Aug 26, 2022
b2c08e0
added a few comments and reorganized code in ContactForm.jsx to impro…
edwinjue Aug 26, 2022
2bb011f
added components/contact/styles/
edwinjue Aug 26, 2022
1ed2871
removed some unused files and comments
edwinjue Aug 26, 2022
d9c09e8
tiny formatting change
edwinjue Aug 26, 2022
799bf10
updated contactForm code per es-lint. added webpack.*.js to .eslintig…
edwinjue Aug 28, 2022
1c80214
replaced Grid justify property with justifyContent
edwinjue Aug 28, 2022
13f76a4
made some changes as per review comments
edwinjue Aug 30, 2022
0df22a7
made some more changes as per review comments
edwinjue Aug 30, 2022
07530cf
made some more changes as per review comments
edwinjue Aug 30, 2022
3414da3
removed a console.log in ContactForm
edwinjue Aug 30, 2022
437c9d2
refactored client/components/contact/ContactImage to make use of make…
edwinjue Aug 31, 2022
f6a54fe
removed explicit comparison to true in ternary operator used by Circu…
edwinjue Aug 31, 2022
95d2a0d
in conditional statements, removed use of type coercion on variables …
edwinjue Sep 1, 2022
8a03971
added early return in onSubmit handler to return false if validation …
edwinjue Sep 1, 2022
ad333f6
updated syntax of early return in onSubmit handler
edwinjue Sep 1, 2022
435d4a4
got rid of methods to dispatch redux actions defined on top and calle…
edwinjue Sep 1, 2022
60bcb80
removed explicit comparison to false in ternary operator used by Button
edwinjue Sep 1, 2022
b13a1d3
tested contact form submission offline. made necessary updates to ens…
edwinjue Sep 2, 2022
0e80c9f
removed comment // response: { status }
edwinjue Sep 3, 2022
ceb9a77
updated fix to metadata.js status is undefined console error
edwinjue Sep 3, 2022
4c2c5c2
removed contact/settings until contact form utilizes more configurati…
edwinjue Sep 3, 2022
aa82a82
reverted /client/redux/reducers/metadata.js and /client/redux/sagas/m…
edwinjue Sep 3, 2022
c1492a0
moved toast to bottom-right
edwinjue Sep 7, 2022
85be5b0
Merge branch 'dev' into 1176-auto-create-issues-of-contact-us-form-me…
edwinjue Sep 7, 2022
95327a6
eslint
edwinjue Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions client/components/contact/ContactForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ const initialFormValues = {
};

const ContactForm = () => {
// Define the methods to dispatch redux actions.
const dispatch = useDispatch();
const callSendGitRequest = useCallback(obj => dispatch(sendGitRequest(obj)), [dispatch]);
const callShowFeedbackSuccess = useCallback(o => dispatch(showFeedbackSuccess(o)), [dispatch]);
const callShowErrorModal = useCallback(obj => dispatch(setErrorModal(obj)), [dispatch]);

// mapStateToProps equivalent.
const displayFeedbackSuccess = useSelector(state => state.ui.displayFeedbackSuccess);
Expand All @@ -48,25 +44,34 @@ const ContactForm = () => {
});
}

function setLoading(isLoading) {
setFormValues(prevState => ({
...prevState,
...{
loading: isLoading,
},
}));
}

// Initialize component.
useEffect(() => {
// ComponentDidMount code goes here...
clearFields();
if (!!displayFeedbackSuccess === true) {
// componentDidMount code goes here...
if (displayFeedbackSuccess) {
toast.success('We received your message. Our team will contact you at the email address provided.', contactSettings.toast.dark);
clearFields();
}

if (!!openErrorModal === true) {
if (openErrorModal) {
toast.error('We failed to process your message. Please try again later.', contactSettings.toast.dark);
setLoading(false);
}

return () => {
// ComponentWillUnmount code goes here...
callShowFeedbackSuccess(false);
callShowErrorModal(false);
clearFields();
// componentWillUnmount code goes here...
dispatch(showFeedbackSuccess(false));
dispatch(setErrorModal(false));
};
}, [callShowErrorModal, callShowFeedbackSuccess, displayFeedbackSuccess, openErrorModal]);
}, [dispatch, displayFeedbackSuccess, openErrorModal]);

// Helper methods.
function validateEmail(emailAddress) {
Expand Down Expand Up @@ -124,26 +129,23 @@ const ContactForm = () => {
const handleSubmit = useCallback(event => {
event.preventDefault();

if (validateForm()) {
const body = [
`First name: ${formValues.firstName.trim()}`,
`Last name: ${formValues.lastName.trim()}`,
`Email: ${formValues.email.trim()}`,
`Association: ${formValues.association.trim() || 'Not provided'}`,
`Message: ${formValues.message.trim()}`,
].join('\n');

setFormValues(prevState => ({
...prevState,
...{
loading: true,
},
}));

// Dispatch action to redux with payload.
callSendGitRequest({ title: formValues.email, body });
if (!validateForm()) {
return;
}
}, [callSendGitRequest,

const body = [
`First name: ${formValues.firstName.trim()}`,
`Last name: ${formValues.lastName.trim()}`,
`Email: ${formValues.email.trim()}`,
`Association: ${formValues.association.trim() || 'Not provided'}`,
`Message: ${formValues.message.trim()}`,
].join('\n');

setLoading(true);

// Dispatch action to redux with payload.
dispatch(sendGitRequest({ title: formValues.email, body }));
}, [dispatch,
formValues.association,
formValues.email,
formValues.firstName,
Expand Down Expand Up @@ -236,7 +238,7 @@ const ContactForm = () => {
</Grid>
<Grid container direction="column" alignItems="center" justifyContent="center" style={{ paddingTop: '8px' }}>
<CircularProgress style={{ display: formValues.loading ? 'block' : 'none' }} />
<Button variant="contained" color="primary" type="submit" style={{ display: formValues.loading === false ? 'block' : 'none' }}>
<Button variant="contained" color="primary" type="submit" style={{ display: formValues.loading ? 'none' : 'block' }}>
Submit
</Button>
</Grid>
Expand Down
5 changes: 3 additions & 2 deletions client/redux/reducers/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export default (state = initialState, action) => {
};
case types.GET_METADATA_FAILURE: {
const {
response: { status },
message,
// response: { status },
edwinjue marked this conversation as resolved.
Show resolved Hide resolved
status,
edwinjue marked this conversation as resolved.
Show resolved Hide resolved
status: { message },
} = action.payload;

return {
Expand Down
3 changes: 1 addition & 2 deletions client/redux/sagas/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import {
types as uiTypes,
setErrorModal,
showDataCharts,
showFeedbackSuccess
} from '../reducers/ui';

Expand Down Expand Up @@ -67,7 +66,7 @@ function* fetchNcByLngLat({ longitude, latitude }) {

function* postFeedback(message) {
const contactURL = `${BASE_URL}/feedback`;

const response = yield call(axios.post, contactURL, message);
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion client/redux/sagas/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function* getMetadata() {
put(getNcGeojsonSuccess(ncGeojsonMetadata)),
]);
} catch (e) {
yield put(getMetadataFailure(e));
yield put(getMetadataFailure({ status: e }));
}
}

Expand Down