Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-05-28 00:12:17 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
56a9c5e0e14240e689a9ee78547f1e9e858397f2
56a9c5e0
1 parent
c44825f1
make useMutation, onSubmit function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
front/src/Routes/Room/RoomContainer.js
front/src/Routes/Room/RoomContainer.js
View file @
56a9c5e
import
React
,
{
useState
}
from
"react"
;
import
{
useQuery
}
from
"@apollo/react-hooks"
;
import
{
useQuery
,
useMutation
}
from
"@apollo/react-hooks"
;
import
{
withRouter
}
from
"react-router-dom"
;
import
RoomPresenter
from
"./RoomPresenter"
;
import
{
GET_ROOMS
}
from
"./RoomQueries"
;
import
{
GET_ROOMS
,
CREATE_ROOM
}
from
"./RoomQueries"
;
import
useInput
from
"../../Hooks/useInput"
;
import
{
toast
}
from
"react-toastify"
;
export
default
withRouter
(()
=>
{
const
[
action
,
setAction
]
=
useState
(
"showList"
);
const
roomName
=
useInput
(
""
);
const
{
data
}
=
useQuery
(
GET_ROOMS
);
let
roomArray
;
const
[
createRoom
]
=
useMutation
(
CREATE_ROOM
);
let
roomArray
,
newRoomObj
;
if
(
data
!==
undefined
)
{
const
{
getRooms
}
=
data
;
roomArray
=
getRooms
;
}
const
onSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
if
(
roomName
.
value
!==
""
)
{
try
{
newRoomObj
=
await
createRoom
({
variables
:
{
name
:
roomName
.
value
}
});
if
(
!
newRoomObj
)
{
// when fail to create room
toast
.
error
(
"fail to create new room"
);
}
else
{
// when success to make room
toast
.
success
(
"success to make new room !"
);
setAction
(
"showList"
);
}
}
catch
{
toast
.
error
(
"occur unexpected error"
);
}
}
else
{
toast
.
error
(
"room name is required !"
);
}
};
return
(
<
RoomPresenter
roomArray
=
{
roomArray
}
action
=
{
action
}
setAction
=
{
setAction
}
onSubmit
=
{
onSubmit
}
roomName
=
{
roomName
}
/
>
);
});
...
...
Please
register
or
login
to post a comment