From 42a71d4592466c79f78d43a856d2e083a5266cb1 Mon Sep 17 00:00:00 2001
From: Neha Gupta <45184761+msnehagup@users.noreply.github.com>
Date: Mon, 29 Apr 2019 16:08:03 -0700
Subject: [PATCH] Show notification when sample is submitted successfully
(#159)
---
.../ClientApp/src/actions/actionTypes.js | 3 +-
.../ClientApp/src/actions/sampleActions.js | 10 +-
.../src/components/Contribute/Contribute.js | 4 +-
...ontributionForm.js => ContributionForm.js} | 101 ++++++++----------
...m.styles.js => ContributionForm.styles.js} | 0
.../src/components/Contribute/SignInDialog.js | 9 +-
.../ClientApp/src/reducers/sampleReducer.js | 2 -
7 files changed, 59 insertions(+), 70 deletions(-)
rename ServerlessLibraryAPI/ClientApp/src/components/Contribute/{AddContributionForm.js => ContributionForm.js} (81%)
rename ServerlessLibraryAPI/ClientApp/src/components/Contribute/{AddContributionForm.styles.js => ContributionForm.styles.js} (100%)
diff --git a/ServerlessLibraryAPI/ClientApp/src/actions/actionTypes.js b/ServerlessLibraryAPI/ClientApp/src/actions/actionTypes.js
index 09730c2..b020270 100644
--- a/ServerlessLibraryAPI/ClientApp/src/actions/actionTypes.js
+++ b/ServerlessLibraryAPI/ClientApp/src/actions/actionTypes.js
@@ -1,6 +1,5 @@
export const sampleActionTypes = {
- GETSAMPLES_SUCCESS: "GETSAMPLES_SUCCESS",
- SAMPLESUBMITTED_SUCCESS: "SAMPLESUBMITTED_SUCCESS"
+ GETSAMPLES_SUCCESS: "GETSAMPLES_SUCCESS"
};
export const userActionTypes = {
diff --git a/ServerlessLibraryAPI/ClientApp/src/actions/sampleActions.js b/ServerlessLibraryAPI/ClientApp/src/actions/sampleActions.js
index ebf61b0..ce9d617 100644
--- a/ServerlessLibraryAPI/ClientApp/src/actions/sampleActions.js
+++ b/ServerlessLibraryAPI/ClientApp/src/actions/sampleActions.js
@@ -1,8 +1,7 @@
import { sampleActionTypes } from "./actionTypes";
export const sampleActions = {
- getSamplesSuccess,
- sampleSubmittedSuccess
+ getSamplesSuccess
};
function getSamplesSuccess(samples) {
@@ -11,10 +10,3 @@ function getSamplesSuccess(samples) {
samples
};
}
-
-function sampleSubmittedSuccess(sample) {
- return {
- type: sampleActionTypes.SAMPLESUBMITTED_SUCCESS,
- sample
- };
-}
diff --git a/ServerlessLibraryAPI/ClientApp/src/components/Contribute/Contribute.js b/ServerlessLibraryAPI/ClientApp/src/components/Contribute/Contribute.js
index bec84d6..9387da6 100644
--- a/ServerlessLibraryAPI/ClientApp/src/components/Contribute/Contribute.js
+++ b/ServerlessLibraryAPI/ClientApp/src/components/Contribute/Contribute.js
@@ -1,5 +1,5 @@
import React, { Component } from "react";
-import AddContributionForm from "./AddContributionForm";
+import ContributionForm from "./ContributionForm";
import ContributionsList from "./ContributionsList";
import SignInDialog from "./SignInDialog";
import PageHeaderWithBackButton from "../shared/PageHeaderWithBackButton";
@@ -17,7 +17,7 @@ class ContributionsPage extends Component {
link.
-
+
diff --git a/ServerlessLibraryAPI/ClientApp/src/components/Contribute/AddContributionForm.js b/ServerlessLibraryAPI/ClientApp/src/components/Contribute/ContributionForm.js
similarity index 81%
rename from ServerlessLibraryAPI/ClientApp/src/components/Contribute/AddContributionForm.js
rename to ServerlessLibraryAPI/ClientApp/src/components/Contribute/ContributionForm.js
index a61c611..905ae06 100644
--- a/ServerlessLibraryAPI/ClientApp/src/components/Contribute/AddContributionForm.js
+++ b/ServerlessLibraryAPI/ClientApp/src/components/Contribute/ContributionForm.js
@@ -1,5 +1,4 @@
import React, { Component } from "react";
-import { connect } from "react-redux";
import {
Icon,
Link,
@@ -11,24 +10,26 @@ import {
} from "office-ui-fabric-react";
import { libraryService } from "../../services";
-import { sampleActions } from "../../actions/sampleActions";
import * as commonStyles from "../shared/Button.styles";
import * as Constants from "../shared/Constants";
const initialState = {
showForm: false,
- errors: [],
- showErrorDialog: false,
title: "",
description: "",
repository: "",
template: "",
technologies: [],
language: "",
- solutionareas: []
+ solutionareas: [],
+ dialogProps: {
+ isVisible: false,
+ title: "",
+ content: {}
+ }
};
-class AddContributionForm extends Component {
+class ContributionForm extends Component {
constructor(props) {
super(props);
@@ -38,7 +39,7 @@ class AddContributionForm extends Component {
this.onAddButtonClick = this.onAddButtonClick.bind(this);
this.onCancelButtonClick = this.onCancelButtonClick.bind(this);
this.handleInputChange = this.handleInputChange.bind(this);
- this.onDismissErrorDialog = this.onDismissErrorDialog.bind(this);
+ this.onDismissDialog = this.onDismissDialog.bind(this);
this.validateForm = this.getFormValidationErrors.bind(this);
}
@@ -102,13 +103,6 @@ class AddContributionForm extends Component {
this.setState({ showForm: true });
}
- setErrorState(errors) {
- this.setState({
- errors: errors,
- showErrorDialog: true
- });
- }
-
onAddButtonClick() {
const sample = {
title: this.state.title,
@@ -121,23 +115,35 @@ class AddContributionForm extends Component {
};
const errors = this.getFormValidationErrors(sample);
if (errors.length > 0) {
- this.setErrorState(errors);
+ this.showDialog("An error occurred!", errors);
return;
}
libraryService
.submitNewSample(sample)
.then(sample => {
- console.log(sample); // todo - give a notification to the user
- this.props.sampleSubmittedSuccess(sample);
this.resetForm();
+ this.showDialog(
+ "Thank you!",
+ "Thank you for your contribution! Your sample has been submitted for approval."
+ );
})
.catch(data => {
- this.setErrorState(data.error);
+ this.showDialog("An error occurred!", data.error);
});
}
- onDismissErrorDialog() {
- this.setState({ showErrorDialog: false });
+ showDialog(title, content) {
+ const dialogProps = {
+ title: title,
+ content: content,
+ isVisible: true
+ };
+ this.setState({ dialogProps });
+ }
+
+ onDismissDialog() {
+ const dialogProps = { ...this.state.dialogProps, isVisible: false };
+ this.setState({ dialogProps });
}
onCancelButtonClick() {
@@ -158,7 +164,7 @@ class AddContributionForm extends Component {
key: s,
text: s
}));
- let { showForm, errors, showErrorDialog } = this.state;
+ let { showForm, dialogProps } = this.state;
return (
@@ -167,27 +173,27 @@ class AddContributionForm extends Component {
Add new contribution
+ {dialogProps.isVisible && (
+
+ )}
{showForm && (
- {showErrorDialog && (
-
- )}