Skip to content

Commit

Permalink
Merge pull request #49 from acmutd/update/editing-alert
Browse files Browse the repository at this point in the history
update/editing-alert
  • Loading branch information
aemmadi authored May 18, 2020
2 parents 7159214 + 204e9e3 commit 38b54ec
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 170 deletions.
42 changes: 11 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,11 @@ import User from "./Components/User/User";
import Pricing from "./Components/Pages/Pricing";
import Error404 from "./Components/Pages/Error404";
import { Route, Switch } from "react-router-dom";
import firebase from "firebase";

const firebaseConfig = {
apiKey: "AIzaSyC10N5kRDieKncmUESxswqkYQ_359f9Qes",
authDomain: "trackit-271619.firebaseapp.com",
databaseURL: "https://trackit-271619.firebaseio.com",
projectId: "trackit-271619",
storageBucket: "trackit-271619.appspot.com",
messagingSenderId: "972365141905",
appId: "1:972365141905:web:fbda064275f635298cec30",
measurementId: "G-HRLPFBGB1E",
};

let app = firebase.initializeApp(firebaseConfig);
import app from "./Components/Firebase/firebase";

function App() {
return (
<div>
{/* replace this with <User /> when wanting to test out the user side, we can decide at a later point when the admin side should appear and when the user side should apper */}
<Switch>
<Route path="/" render = {(props) => <User database = {app} />} exact />
<Route path="/admin" render = {(props) => <Admin database = {app} />} exact />
Expand Down
62 changes: 59 additions & 3 deletions src/Components/Admin/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Admin extends React.Component {
workshop_data: null,
student_data: null,
dataLoaded: false,

alert: false,
alertText: "Unknown error occured",
};

/**
Expand All @@ -41,7 +44,6 @@ class Admin extends React.Component {
.then((doc) => {
// if the user has admin acess then set loggedIn to true
if (doc.data().isAdmin === true) {
console.log("logging user in");
this.setState({
loggedIn: true,
});
Expand All @@ -62,6 +64,10 @@ class Admin extends React.Component {
}
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in login process",
});
console.log(error + " error occurred in login process");
});
}
Expand Down Expand Up @@ -168,6 +174,10 @@ class Admin extends React.Component {
console.log("workshop level successfully updated");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in updating workshop level",
});
console.log(error + " error occurred in updating workshop level");
});
};
Expand All @@ -190,6 +200,10 @@ class Admin extends React.Component {
console.log("workshop status successfully updated");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in updating workshop status",
});
console.log(error + " error occurred in updating workshop status");
});
};
Expand All @@ -211,6 +225,10 @@ class Admin extends React.Component {
console.log("All student progress successfully cleared");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in erasing student progress",
});
console.log(error + " error occured in erasing student progress");
});
};
Expand All @@ -237,6 +255,10 @@ class Admin extends React.Component {
console.log("updating workshop successful");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in updating workshop",
});
console.log(error + " error occurred in updating workshop");
});

Expand All @@ -252,6 +274,10 @@ class Admin extends React.Component {
console.log("workshop level successfully reset to 1");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in reseting workshop level to 1",
});
console.log(error + " error occurred in reseting workshop level to 1");
});
};
Expand Down Expand Up @@ -279,6 +305,10 @@ class Admin extends React.Component {
console.log("empty students at workshop entry created");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in adding empty students at workshop object",
});
console.log(
error + " error occured in adding empty sudents at workshop object"
);
Expand All @@ -294,6 +324,10 @@ class Admin extends React.Component {
console.log("new workshop created");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in creating new workshop",
});
console.log(error + " error occurred in creating new workshop");
});
};
Expand All @@ -312,6 +346,10 @@ class Admin extends React.Component {
console.log("successfully deleted students at workshop");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in deleting students at workshop",
});
console.log(error + " error occurred in deleting students at workshop");
});

Expand All @@ -324,6 +362,10 @@ class Admin extends React.Component {
console.log("successfully deleted workshop");
})
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in deleting workshop",
});
console.log(error + " error occurred in deleting workshop");
});
};
Expand All @@ -345,11 +387,22 @@ class Admin extends React.Component {
dataLoaded: false,
});
})
.catch((err) => {
console.log("error signing user out");
.catch((error) => {
this.setState({
alert: true,
alertText: error + " Error occurred in signing out the user",
});
console.log(error + " error signing user out");
});
};

resetAlertStatus = () => {
this.setState({
alert: false,
alertText: "Unknown error occurred",
})
}

/**
* renders the page
*/
Expand All @@ -374,6 +427,9 @@ class Admin extends React.Component {
workshopListener={this.workshopListener}
signOut={this.signOutUser}
dataLoaded={this.state.workshop_data && this.state.student_data}
alert={this.state.alert}
alertText={this.state.alertText}
resetAlertStatus={this.resetAlertStatus}
/>
) : (
<AdminAuth
Expand Down
Loading

0 comments on commit 38b54ec

Please sign in to comment.