Skip to content

Commit 367c8c6

Browse files
authored
Merge pull request #28 from Visual-Regression-Tracker/73-register-error
73 register error
2 parents a9526bc + d39151c commit 367c8c6

23 files changed

+341
-199
lines changed

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@testing-library/user-event": "^7.2.1",
1212
"konva": "^4.2.2",
1313
"material-ui-popup-state": "^1.6.1",
14+
"notistack": "^0.9.17",
1415
"qs": "^6.9.4",
1516
"react": "^16.13.1",
1617
"react-debounce-input": "^3.2.2",

src/App.jsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import { SnackbarProvider } from 'notistack';
23
import "./App.css";
34
import Header from "./components/Header";
45
import {
@@ -12,20 +13,22 @@ import { SocketProvider } from "./contexts/socket.context";
1213

1314
function App() {
1415
return (
15-
<div className="App">
16-
<AuthProvider>
17-
<ProjectProvider>
18-
<BuildProvider>
19-
<TestRunProvider>
20-
<SocketProvider>
21-
<Header />
22-
<Router />
23-
</SocketProvider>
24-
</TestRunProvider>
25-
</BuildProvider>
26-
</ProjectProvider>
27-
</AuthProvider>
28-
</div>
16+
<SnackbarProvider maxSnack={3}>
17+
<div className="App">
18+
<AuthProvider>
19+
<ProjectProvider>
20+
<BuildProvider>
21+
<TestRunProvider>
22+
<SocketProvider>
23+
<Header />
24+
<Router />
25+
</SocketProvider>
26+
</TestRunProvider>
27+
</BuildProvider>
28+
</ProjectProvider>
29+
</AuthProvider>
30+
</div>
31+
</SnackbarProvider>
2932
);
3033
}
3134

src/components/BuildList.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { BuildStatusChip } from "./BuildStatusChip";
2424
import { SkeletonList } from "./SkeletonList";
2525
import { formatDateTime } from "../_helpers/format.helper";
26+
import { useSnackbar } from "notistack";
2627

2728
const useStyles = makeStyles((theme: Theme) =>
2829
createStyles({
@@ -42,6 +43,7 @@ const BuildList: FunctionComponent = () => {
4243
const history = useHistory();
4344
const { buildList, selectedBuildId, loading } = useBuildState();
4445
const buildDispatch = useBuildDispatch();
46+
const { enqueueSnackbar } = useSnackbar();
4547

4648
return (
4749
<List>
@@ -98,7 +100,17 @@ const BuildList: FunctionComponent = () => {
98100
>
99101
<IconButton
100102
onClick={() => {
101-
deleteBuild(buildDispatch, build.id);
103+
deleteBuild(buildDispatch, build.id)
104+
.then((b) =>
105+
enqueueSnackbar(`${b.id} removed`, {
106+
variant: "success",
107+
})
108+
)
109+
.catch((err) =>
110+
enqueueSnackbar(err, {
111+
variant: "error",
112+
})
113+
);
102114
}}
103115
>
104116
<Delete />

src/components/LoginForm.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ import {
1111
} from "@material-ui/core";
1212
import { useAuthDispatch, login } from "../contexts";
1313
import { routes } from "../constants";
14+
import { useSnackbar } from "notistack";
1415

1516
const LoginForm = () => {
17+
const { enqueueSnackbar } = useSnackbar();
1618
const [email, setEmail] = useState("");
1719
const [password, setPassword] = useState("");
1820
const dispatch = useAuthDispatch();
1921

2022
const handleSubmit = (event: FormEvent) => {
2123
event.preventDefault();
22-
login(dispatch, email, password);
24+
login(dispatch, email, password).catch((err) =>
25+
enqueueSnackbar(err, {
26+
variant: "error",
27+
})
28+
);
2329
};
2430

2531
return (

src/components/RegisterForm.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {
99
} from "@material-ui/core";
1010
import { useAuthDispatch, login } from "../contexts";
1111
import { usersService } from "../services";
12+
import { useSnackbar } from "notistack";
1213

1314
const RegisterForm = () => {
15+
const { enqueueSnackbar } = useSnackbar();
1416
const [email, setEmail] = useState("");
1517
const [firstName, setFirstName] = useState("");
1618
const [lastName, setLastName] = useState("");
@@ -21,7 +23,12 @@ const RegisterForm = () => {
2123
event.preventDefault();
2224
usersService
2325
.register(firstName, lastName, email, password)
24-
.then(() => login(dispatch, email, password));
26+
.then(() => login(dispatch, email, password))
27+
.catch((err) =>
28+
enqueueSnackbar(err, {
29+
variant: "error",
30+
})
31+
);
2532
};
2633

2734
return (

src/components/TestDetailsModal.tsx

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { routes } from "../constants";
4040
import { useTestRunDispatch, updateTestRun, selectTestRun } from "../contexts";
4141
import { DrawArea } from "./DrawArea";
4242
import { CommentsPopper } from "./CommentsPopper";
43+
import { useSnackbar } from "notistack";
4344

4445
const useStyles = makeStyles((theme) => ({
4546
imageContainer: {
@@ -57,6 +58,7 @@ const TestDetailsModal: React.FunctionComponent<{
5758
}> = ({ testRun }) => {
5859
const classes = useStyles();
5960
const history = useHistory();
61+
const { enqueueSnackbar } = useSnackbar();
6062
const testRunDispatch = useTestRunDispatch();
6163

6264
const stageWidth = (window.innerWidth / 2) * 0.9;
@@ -177,6 +179,16 @@ const TestDetailsModal: React.FunctionComponent<{
177179
.then((testRun) => {
178180
updateTestRun(testRunDispatch, testRun);
179181
})
182+
.then(() =>
183+
enqueueSnackbar("Approved", {
184+
variant: "success",
185+
})
186+
)
187+
.catch((err) =>
188+
enqueueSnackbar(err, {
189+
variant: "error",
190+
})
191+
)
180192
}
181193
>
182194
Approve
@@ -186,9 +198,21 @@ const TestDetailsModal: React.FunctionComponent<{
186198
<Button
187199
color="secondary"
188200
onClick={() =>
189-
testRunService.reject(testRun.id).then((testRun) => {
190-
updateTestRun(testRunDispatch, testRun);
191-
})
201+
testRunService
202+
.reject(testRun.id)
203+
.then((testRun) => {
204+
updateTestRun(testRunDispatch, testRun);
205+
})
206+
.then(() =>
207+
enqueueSnackbar("Rejected", {
208+
variant: "success",
209+
})
210+
)
211+
.catch((err) =>
212+
enqueueSnackbar(err, {
213+
variant: "error",
214+
})
215+
)
192216
}
193217
>
194218
Reject
@@ -239,6 +263,16 @@ const TestDetailsModal: React.FunctionComponent<{
239263
comment
240264
),
241265
])
266+
.then(() =>
267+
enqueueSnackbar("Comment updated", {
268+
variant: "success",
269+
})
270+
)
271+
.catch((err) =>
272+
enqueueSnackbar(err, {
273+
variant: "error",
274+
})
275+
)
242276
}
243277
/>
244278
</Grid>
@@ -274,25 +308,39 @@ const TestDetailsModal: React.FunctionComponent<{
274308
<Grid item>
275309
<IconButton
276310
disabled={isIgnoreAreasSaved()}
277-
onClick={() => {
278-
// update in test run
279-
testRunService
280-
.setIgnoreAreas(testRun.id, ignoreAreas)
281-
.then(() =>
311+
onClick={() =>
312+
Promise.all([
313+
// update in test run
314+
testRunService.setIgnoreAreas(testRun.id, ignoreAreas),
315+
// update in variation
316+
testVariationService.setIgnoreAreas(
317+
testRun.testVariationId,
318+
ignoreAreas
319+
),
320+
])
321+
.then(() => {
322+
enqueueSnackbar("Ignore areas are updated", {
323+
variant: "success",
324+
});
325+
282326
// recalculate diff
283327
testRunService
284328
.recalculateDiff(testRun.id)
285329
.then((testRun) =>
286330
updateTestRun(testRunDispatch, testRun)
287331
)
288-
);
289-
290-
// update in variation
291-
testVariationService.setIgnoreAreas(
292-
testRun.testVariationId,
293-
ignoreAreas
294-
);
295-
}}
332+
.then(() =>
333+
enqueueSnackbar("Diff recalculated", {
334+
variant: "success",
335+
})
336+
);
337+
})
338+
.catch((err) =>
339+
enqueueSnackbar(err, {
340+
variant: "error",
341+
})
342+
)
343+
}
296344
>
297345
<Save />
298346
</IconButton>

src/components/TestRunList.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import {
2525
} from "../contexts";
2626
import { Skeleton } from "@material-ui/lab";
2727
import { SkeletonList } from "./SkeletonList";
28+
import { useSnackbar } from "notistack";
2829

2930
const TestRunList: React.FunctionComponent<{
3031
items: TestRun[];
3132
}> = ({ items }) => {
33+
const { enqueueSnackbar } = useSnackbar();
3234
const { selectedTestRunId, loading } = useTestRunState();
3335
const testRunDispatch = useTestRunDispatch();
3436
const history = useHistory();
@@ -134,7 +136,17 @@ const TestRunList: React.FunctionComponent<{
134136
</MenuItem>
135137
<MenuItem
136138
onClick={() => {
137-
deleteTestRun(testRunDispatch, selectedTestRun.id);
139+
deleteTestRun(testRunDispatch, selectedTestRun.id)
140+
.then((testRun) => {
141+
enqueueSnackbar(`Deleted`, {
142+
variant: "success",
143+
});
144+
})
145+
.catch((err) =>
146+
enqueueSnackbar(err, {
147+
variant: "error",
148+
})
149+
);
138150
handleClose();
139151
}}
140152
>

src/components/TestVariationMergeForm.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Grid, Select, MenuItem, Button } from "@material-ui/core";
33
import { testVariationService } from "../services";
44
import { useHistory } from "react-router-dom";
55
import { buildBuildPageUrl } from "../_helpers/route.helpers";
6+
import { useSnackbar } from "notistack";
67

78
interface IProps {
89
projectId: string;
@@ -14,13 +15,24 @@ export const TestVariationMergeForm: React.FunctionComponent<IProps> = ({
1415
items,
1516
}) => {
1617
const history = useHistory();
18+
const { enqueueSnackbar } = useSnackbar();
1719
const [branch, setBranch] = React.useState("");
1820

1921
const handleSubmit = (event: React.FormEvent) => {
2022
event.preventDefault();
21-
testVariationService.merge(projectId, branch).then((build) => {
22-
history.push(buildBuildPageUrl(projectId, build.id));
23-
});
23+
testVariationService
24+
.merge(projectId, branch)
25+
.then((build) => {
26+
enqueueSnackbar(`Merge started in build: ${build.id}`, {
27+
variant: "success",
28+
});
29+
history.push(buildBuildPageUrl(projectId, build.id));
30+
})
31+
.catch((err) =>
32+
enqueueSnackbar(err, {
33+
variant: "error",
34+
})
35+
);
2436
};
2537

2638
return (

0 commit comments

Comments
 (0)