Last change
on this file since ac19a0c was ac19a0c, checked in by darsov2 <62809499+darsov2@…>, 9 months ago |
authContext impl, admin panel impl, search bar fixes, reservations listings impl
|
-
Property mode
set to
100644
|
File size:
1009 bytes
|
Rev | Line | |
---|
[e9b4ba9] | 1 | import React from "react";
|
---|
| 2 | import axios from "../../../axios";
|
---|
| 3 | import { useNavigate } from 'react-router-dom';
|
---|
| 4 |
|
---|
| 5 | const useCreateRestaurant = () => {
|
---|
| 6 |
|
---|
| 7 | const navigator = useNavigate();
|
---|
| 8 |
|
---|
| 9 | const createRestaurant = async (restaurant, edit) => {
|
---|
| 10 | console.log(restaurant)
|
---|
| 11 | if(!edit)
|
---|
| 12 | {
|
---|
| 13 | console.log(restaurant)
|
---|
| 14 | await axios
|
---|
| 15 | .post(`/restaurant/add`, restaurant, {
|
---|
| 16 | params: {
|
---|
[ac19a0c] | 17 | userId: JSON.parse(localStorage.getItem('user')).userId,
|
---|
[e9b4ba9] | 18 | }
|
---|
| 19 | })
|
---|
| 20 | .then((res) => {
|
---|
| 21 | // console.log(res)
|
---|
| 22 | // window.location.reload()
|
---|
| 23 | })
|
---|
| 24 | .catch((err) => {
|
---|
| 25 | console.log(err);
|
---|
| 26 | })
|
---|
| 27 | .finally(() => {
|
---|
| 28 | });
|
---|
| 29 | }
|
---|
| 30 | else
|
---|
| 31 | {
|
---|
| 32 | await axios
|
---|
| 33 | .post(`/restaurant/edit`, restaurant)
|
---|
| 34 | .then((res) => {
|
---|
| 35 | console.log(res)
|
---|
| 36 | //window.location.reload()
|
---|
| 37 | //navigator("/resources/restaurant")
|
---|
| 38 | //history.push('/restaurant');
|
---|
| 39 | })
|
---|
| 40 | .catch((err) => {
|
---|
| 41 | console.log(err);
|
---|
| 42 | })
|
---|
| 43 | .finally(() => {
|
---|
| 44 | });
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | return {
|
---|
| 50 | createRestaurant
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | export default useCreateRestaurant; |
---|
Note:
See
TracBrowser
for help on using the repository browser.