Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plan-puzzle
client
Commits
a4f1d35c
Commit
a4f1d35c
authored
1 year ago
by
유 채린
Browse files
Options
Downloads
Patches
Plain Diff
feat: upload add vote schedule
parent
ca762a71
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/recruit/vote.js
+16
-10
16 additions, 10 deletions
src/components/recruit/vote.js
with
16 additions
and
10 deletions
src/components/recruit/vote.js
+
16
−
10
View file @
a4f1d35c
...
@@ -2,19 +2,23 @@ import React, { useState, useEffect, useContext } from "react";
...
@@ -2,19 +2,23 @@ import React, { useState, useEffect, useContext } from "react";
import
voteStyles
from
'
./vote.module.css
'
import
voteStyles
from
'
./vote.module.css
'
import
{
AuthContext
}
from
"
../../App
"
;
import
{
AuthContext
}
from
"
../../App
"
;
function
VoteItem
({
data
,
setCheckVote
}){
function
VoteItem
({
data
,
setCheckVote
,
setAddSchedule
}){
const
[
isChecked
,
setIsChecked
]
=
useState
(
false
);
const
[
isChecked
,
setIsChecked
]
=
useState
(
false
);
const
onChangeCheck
=
()
=>
{
const
onChangeCheck
=
()
=>
{
if
(
!
isChecked
)
{
if
(
!
isChecked
)
{
setCheckVote
((
prev
)
=>
[...
prev
,
data
.
id
]);
setCheckVote
((
prev
)
=>
[...
prev
,
data
.
id
]);
setAddSchedule
((
prev
)
=>
[...
prev
,
data
.
id
]);
setIsChecked
((
prev
)
=>
!
prev
);
setIsChecked
((
prev
)
=>
!
prev
);
}
else
{
}
else
{
setCheckVote
((
prev
)
=>
setCheckVote
((
prev
)
=>
prev
.
filter
((
vote
)
=>
(
prev
.
filter
((
vote
)
=>
(
vote
.
date
!==
data
.
date
||
vote
!==
data
.
id
vote
.
startTime
!==
data
.
startTime
||
))
vote
.
endTime
!==
data
.
endTime
);
setAddSchedule
((
prev
)
=>
prev
.
filter
((
vote
)
=>
(
vote
!==
data
.
id
))
))
);
);
setIsChecked
((
prev
)
=>
!
prev
);
setIsChecked
((
prev
)
=>
!
prev
);
...
@@ -41,6 +45,7 @@ function Vote({ isOpen, onClose, data }) {
...
@@ -41,6 +45,7 @@ function Vote({ isOpen, onClose, data }) {
const
[
votedata
,
setVotedata
]
=
useState
([]);
const
[
votedata
,
setVotedata
]
=
useState
([]);
const
[
checkVote
,
setCheckVote
]
=
useState
([]);
const
[
checkVote
,
setCheckVote
]
=
useState
([]);
const
[
count
,
setCount
]
=
useState
(
0
);
const
[
count
,
setCount
]
=
useState
(
0
);
const
[
addSchedule
,
setAddSchedule
]
=
useState
([]);
const
{
userData
}
=
useContext
(
AuthContext
);
const
{
userData
}
=
useContext
(
AuthContext
);
...
@@ -52,7 +57,7 @@ function Vote({ isOpen, onClose, data }) {
...
@@ -52,7 +57,7 @@ function Vote({ isOpen, onClose, data }) {
if
(
response
.
ok
){
if
(
response
.
ok
){
if
(
jsonData
.
length
>
0
)
{
if
(
jsonData
.
length
>
0
)
{
const
components
=
jsonData
.
map
((
data
)
=>
(
const
components
=
jsonData
.
map
((
data
)
=>
(
<
VoteItem
data
=
{
data
}
setCheckVote
=
{
setCheckVote
}
/
>
<
VoteItem
data
=
{
data
}
setCheckVote
=
{
setCheckVote
}
setAddSchedule
=
{
setAddSchedule
}
/
>
));
));
setVotedata
(
components
);
setVotedata
(
components
);
...
@@ -61,7 +66,7 @@ function Vote({ isOpen, onClose, data }) {
...
@@ -61,7 +66,7 @@ function Vote({ isOpen, onClose, data }) {
setVotedata
(
components
);
setVotedata
(
components
);
}
}
}
else
{
}
else
{
alert
(
"
투표 조회 실패
"
);
alert
(
"
투표 조회
를
실패
하였습니다.
"
);
}
}
}
catch
(
error
){
}
catch
(
error
){
...
@@ -83,7 +88,7 @@ function Vote({ isOpen, onClose, data }) {
...
@@ -83,7 +88,7 @@ function Vote({ isOpen, onClose, data }) {
alert
(
"
투표되었습니다.
"
);
alert
(
"
투표되었습니다.
"
);
setCount
((
prev
)
=>
(
prev
+
1
));
setCount
((
prev
)
=>
(
prev
+
1
));
}
else
{
}
else
{
throw
new
Error
(
'
Data loading error
'
);
alert
(
"
투표를 실패하였습니다.
"
);
}
}
}
catch
(
error
){
}
catch
(
error
){
console
.
log
(
'
Error during fetch:
'
,
error
);
console
.
log
(
'
Error during fetch:
'
,
error
);
...
@@ -93,17 +98,18 @@ function Vote({ isOpen, onClose, data }) {
...
@@ -93,17 +98,18 @@ function Vote({ isOpen, onClose, data }) {
const
endVote
=
async
()
=>
{
const
endVote
=
async
()
=>
{
try
{
try
{
const
response
=
await
fetch
(
`/api/recruits/
${
data
.
id
}
/times/vote`
,{
const
response
=
await
fetch
(
`/api/recruits/
${
data
.
id
}
/times/vote`
,{
method
:
'
P
U
T
'
,
method
:
'
P
OS
T
'
,
headers
:
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
},
body
:
JSON
.
stringify
({
"
idList
"
:
addSchedule
}),
});
});
if
(
response
.
ok
){
if
(
response
.
ok
){
alert
(
"
투표
가
마감되었습니다.
"
);
alert
(
"
투표 마감
후 스케줄이 성공적으로 추가
되었습니다.
"
);
window
.
location
.
reload
();
window
.
location
.
reload
();
}
else
{
}
else
{
throw
new
Error
(
'
Data loading error
'
);
alert
(
'
스케줄이 중복된 모집원이 존재합니다.
'
);
}
}
}
catch
(
error
){
}
catch
(
error
){
console
.
log
(
'
Error during fetch:
'
,
error
);
console
.
log
(
'
Error during fetch:
'
,
error
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment