FInalize async/await changes

This commit is contained in:
oitsjustjose 2021-07-02 21:05:34 -05:00
commit 60e507fae3
2 changed files with 10 additions and 11 deletions

View file

@ -1,7 +1,7 @@
import axios from 'axios'; import axios from 'axios';
import { routes } from '../App'; import { routes } from '../App';
export default async (url, slug) => { export default async ({ url, slug }) => {
const paths = routes.map(({ path }) => path.substr(1)); const paths = routes.map(({ path }) => path.substr(1));
if (slug && paths.includes(slug)) { if (slug && paths.includes(slug)) {
return null; return null;

View file

@ -14,13 +14,13 @@ export default () => {
error: false, error: false,
}); });
const submit = (evt) => { const submit = async (evt) => {
evt.preventDefault(); evt.preventDefault();
if (state.url) { if (state.url) {
setState({ ...state, loading: true }); setState({ ...state, loading: true });
putUrlHandler(
state.url, state.slug, try {
).then((data) => { const data = await putUrlHandler(state);
if (data) { if (data) {
setState({ setState({
...state, ...state,
@ -33,10 +33,11 @@ export default () => {
...state, ...state,
result: null, result: null,
loading: false, loading: false,
error: 'There is a conflict with this slug. Please try a different one!', error:
'There is a conflict with this slug. Please try a different one!',
}); });
} }
}).catch((ex) => { } catch (ex) {
if (ex.response?.data?.error) { if (ex.response?.data?.error) {
setState({ setState({
...state, ...state,
@ -45,7 +46,7 @@ export default () => {
error: ex.response.data.error, error: ex.response.data.error,
}); });
} }
}); }
} }
}; };
@ -81,9 +82,7 @@ export default () => {
</Form> </Form>
{state.error && ( {state.error && (
<h5 className="text-center text-danger"> <h5 className="text-center text-danger">{state.error}</h5>
{state.error}
</h5>
)} )}
{state.result && ( {state.result && (