Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Surrey Board
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
COM3014
Surrey Board
Merge requests
!24
merge
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
merge
Armand
into
main
Overview
0
Commits
26
Pipelines
0
Changes
9
Merged
Oral, Armand (PG/T - Comp Sci & Elec Eng)
requested to merge
Armand
into
main
3 years ago
Overview
0
Commits
26
Pipelines
0
Changes
9
Expand
merge
0
0
Merge request reports
Compare
main
version 1
5adf7e85
3 years ago
main (base)
and
latest version
latest version
c7c626c7
26 commits,
3 years ago
version 1
5adf7e85
25 commits,
3 years ago
9 files
+
246
−
59
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
front-end/src/components/CreatePost/CreatePost.js
+
90
−
22
Options
import
{
useState
}
from
"
react
"
;
import
Axios
from
"
axios
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
React
,
{
useContext
,
useEffect
}
from
"
react
"
;
import
{
Form
,
FormGroup
,
@@ -9,36 +10,68 @@ import {
Row
,
Col
,
Card
,
Dropdown
,
Alert
}
from
"
react-bootstrap
"
;
const
user_values
=
JSON
.
parse
(
localStorage
.
getItem
(
"
user
"
));
//console.log(user_values._id)
function
CreatePost
()
{
const
[
postTitle
,
setTitle
]
=
useState
(
""
);
const
[
postContent
,
setContent
]
=
useState
(
""
);
const
[
Society
,
getSociety
]
=
useState
([]);
const
[
postSociety
,
setSociety
]
=
useState
(
""
);
const
[
postEvent
,
setEvent
]
=
useState
(
Boolean
);
const
[
error
,
setError
]
=
useState
();
const
[
show
,
setShow
]
=
useState
(
false
);
const
user_id
=
user_values
.
_id
;
const
navigate
=
useNavigate
();
//const {state, dispatch} = useContext(LoginContext)
const
handleSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
setShow
(
false
);
const
post
=
{
title
:
postTitle
,
content
:
postContent
,
society
:
postSociety
,
isEvent
:
postEvent
,
user
:
user_id
};
const
res
=
await
Axios
.
post
(
"
http://localhost:3006/post
"
,
post
);
console
.
log
(
res
.
data
.
message
)
console
.
log
(
post
.
society
)
if
(
res
.
data
.
message
==
'
post added
'
)
{
navigate
(
"
/homepage
"
);
}
else
{
setError
(
res
.
data
.
message
);
setShow
(
true
);
}
const
handleSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
const
post
=
{
title
:
postTitle
,
content
:
postContent
,
};
const
res
=
await
Axios
.
post
(
"
http://localhost:3006/post
"
,
post
);
console
.
log
(
res
.
data
.
message
)
if
(
res
.
data
.
message
==
'
post added
'
){
navigate
(
"
/homepage
"
);
}
else
{
// TODO: add validation for if request comes back bad
}
};
useEffect
(()
=>
{
Axios
.
get
(
"
http://localhost:3007/society/showall
"
).
then
((
data
)
=>
{
getSociety
(
data
.
data
)
console
.
log
(
data
.
data
)
});
},
[]);
return
(
<
Container
fluid
=
"
lg
"
>
<
br
/>
<
Form
onSubmit
=
{
handleSubmit
}
>
<
h1
className
=
"
center-text
"
>
New
Post
<
/h1
>
{
show
&&
(
<
Alert
onClose
=
{()
=>
setShow
(
false
)}
variant
=
"
danger
"
dismissible
>
<
Alert
.
Heading
>
{
error
}
<
/Alert.Heading
>
<
/Alert
>
)}
<
Card
className
=
"
card-padding
"
>
<
Row
>
<
Card
.
Body
>
@@ -55,33 +88,68 @@ function CreatePost() {
<
/Form.Group
>
<
/Card.Body
>
<
/Row
>
<
Row
>
<
Card
.
Body
>
<
Form
.
Group
className
=
"
mb-3
"
controlId
=
"
formDescription
"
>
<
Form
.
Label
>
Description
<
/Form.Label
>
<
div
className
=
"
form-group
"
>
<
textarea
className
=
"
form-control
"
type
=
"
text
"
placeholder
=
"
Enter description
"
id
=
"
description
"
rows
=
"
4
"
onChange
=
{(
e
)
=>
{
e
.
preventDefault
();
setContent
(
e
.
target
.
value
);
}}
/
>
<
/div
>
<
/Form.Group
>
<
/Card.Body
>
<
/Row
>
<
Row
>
<
Card
.
Body
>
<
Form
.
Group
className
=
"
mb-3
"
controlId
=
"
formSociety
"
>
<
Form
.
Label
>
Society
<
/Form.Label
>
<
div
className
=
"
form-group
"
>
<
select
id
=
'
society
'
onChange
=
{(
e
)
=>
{
e
.
preventDefault
();
setSociety
(
e
.
target
.
value
);
}}
>
{
Society
.
map
((
value
,
key
)
=>
{
return
(
<
option
key
=
{
key
}
value
=
{
value
.
_id
}
>
{
value
.
name
}
<
/option
>
)
})}
<
option
>
Select
<
/option
>
<
/select
>
<
/div
>
<
/Form.Group
>
<
/Card.Body
>
<
/Row
>
<
Row
>
<
Card
.
Body
>
<
Form
.
Group
className
=
"
mb-3
"
controlId
=
"
formEvent
"
>
<
Form
.
Label
>
Check
the
box
below
if
the
post
is
about
an
event
:
<
/Form.Label
>
<
div
className
=
"
form-group
"
>
<
input
type
=
"
checkbox
"
onChange
=
{(
e
)
=>
{
e
.
preventDefault
();
setEvent
(
e
.
target
.
checked
);
}}
/
>
<
/div
>
<
/Form.Group
>
<
/Card.Body
>
<
/Row
>
<
div
id
=
"
align-center
"
>
<
Button
type
=
"
submit
"
size
=
"
lg
"
>
Submit
<
/Button
>
<
Button
type
=
"
submit
"
size
=
"
lg
"
>
Submit
<
/Button
>
<
/div
>
<
br
/>
<
/Card
>
<
/Form
>
<
/Container
>
Loading