Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vt-research-connect-frontend
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cscapstone-group3
vt-research-connect-frontend
Commits
d59ba249
Commit
d59ba249
authored
7 months ago
by
hannahl8
Browse files
Options
Downloads
Patches
Plain Diff
fix delete dicussion on item page to navigate back to discussion
add delete button for openings
parent
ffcb1440
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#10849
passed
7 months ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/OpeningListItem.tsx
+26
-2
26 additions, 2 deletions
src/components/OpeningListItem.tsx
src/services.ts
+9
-0
9 additions, 0 deletions
src/services.ts
with
35 additions
and
2 deletions
src/components/OpeningListItem.tsx
+
26
−
2
View file @
d59ba249
...
...
@@ -3,7 +3,11 @@ import "./OpeningListItem.css"
import
{
useState
}
from
"
react
"
;
import
OpeningPopup
from
"
./OpeningPopup.tsx
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
dateTimeFormatOptions
,
profilePagePath
}
from
"
../utils.ts
"
;
import
{
ADMIN_ROLE
,
dateTimeFormatOptions
,
NO_TOKEN
,
profilePagePath
}
from
"
../utils.ts
"
;
import
{
useUserContext
}
from
"
../contexts/UserContext.tsx
"
;
import
{
useProfessorUserContext
}
from
"
../contexts/ProfessorUserContext.tsx
"
;
import
{
deleteOpening
}
from
"
../services.ts
"
;
import
{
useOpeningsContext
}
from
"
../contexts/OpeningsContext.tsx
"
;
export
default
function
OpeningListItem
(
props
:
{
opening
:
OpeningsItem
})
{
const
id
=
props
.
opening
.
id
;
...
...
@@ -14,12 +18,29 @@ export default function OpeningListItem(props: { opening: OpeningsItem }) {
const
createdAtDate
=
new
Date
(
props
.
opening
.
createdAt
);
const
createdAtString
=
createdAtDate
.
toLocaleString
(
'
en-US
'
,
dateTimeFormatOptions
);
const
professorName
=
`
${
props
.
opening
.
professor
.
firstName
}
${
props
.
opening
.
professor
.
lastName
}
`
const
{
token
,
role
}
=
useUserContext
();
const
{
professor
}
=
useProfessorUserContext
();
const
{
refreshOpenings
}
=
useOpeningsContext
();
const
[
showPopup
,
setShowPopup
]
=
useState
(
false
);
const
togglePopup
=
()
=>
{
setShowPopup
(
!
showPopup
);
};
function
handleDeleteOpeningsClick
()
{
if
(
token
!==
NO_TOKEN
)
{
deleteOpening
(
id
,
token
)
.
then
(()
=>
{
refreshOpenings
(
""
);
// refresh discussions after deletion
console
.
log
(
'
Opening deleted successfully
'
);
})
.
catch
((
error
)
=>
{
// Handle error
console
.
error
(
'
Failed to delete discussion:
'
,
error
);
});
}
}
return
(
<>
<
li
key
=
{
id
}
className
=
"opening-item"
>
...
...
@@ -28,7 +49,10 @@ export default function OpeningListItem(props: { opening: OpeningsItem }) {
<
p
className
=
"opening-details"
><
Link
to
=
{
`
${
profilePagePath
}
/PROFESSOR/
${
professorName
}
`
}
>
{
professorName
}
</
Link
>
posted a
<
strong
>
{
type
}
</
strong
>
opportunity on
{
createdAtString
}
</
p
>
{
(
role
===
ADMIN_ROLE
||
professorName
===
`
${
professor
?.
firstName
}
${
professor
?.
lastName
}
`
)
&&
(
<
button
className
=
{
'
delete-comment-button tertiary-button
'
}
onClick
=
{
handleDeleteOpeningsClick
}
>
Delete
</
button
>
)
}
</
li
>
{
showPopup
&&
(
<
OpeningPopup
opening
=
{
props
.
opening
}
onClose
=
{
togglePopup
}
/>
...
...
This diff is collapsed.
Click to expand it.
src/services.ts
+
9
−
0
View file @
d59ba249
...
...
@@ -100,6 +100,15 @@ export const fetchOpenings = async (token: string): Promise<OpeningsItem[]> => {
return
response
.
data
as
OpeningsItem
[];
}
export
const
deleteOpening
=
async
(
id
:
number
,
token
:
string
)
=>
{
const
response
=
await
axios
.
delete
(
`
${
openingsAPI
}
/
${
id
}
`
,
{
headers
:
{
'
Authorization
'
:
`Bearer
${
token
}
`
,
}
});
return
response
;
};
export
const
fetchDiscussions
=
async
(
token
:
string
):
Promise
<
DiscussionItem
[]
>
=>
{
const
response
=
await
axios
.
get
(
`
${
discussionsAPI
}
`
,
{
headers
:
{
...
...
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