Skip to content

Commit

Permalink
Add approve button to allow approvers to do it with single click
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksTeresh committed Dec 18, 2024
1 parent d5bd774 commit 6eb5daf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/client/components/ThesisPage/ViewThesisFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ import usePrograms from '../../hooks/usePrograms'
import useEvents from '../../hooks/useEvents'
import { useSingleThesis } from '../../hooks/useTheses'

import { BASE_PATH } from '../../../config'
import { BASE_PATH, THESIS_STATUSES } from '../../../config'
import EventsView from '../EventsView/EventsView'
import { useState } from 'react'
import { ExpandLess, ExpandMore } from '@mui/icons-material'
import { useEditThesisMutation } from '../../hooks/useThesesMutation'
import useLoggedInUser from '../../hooks/useLoggedInUser'

const IN_PROGRESS_STATUS = THESIS_STATUSES.IN_PROGRESS as 'IN_PROGRESS'

const StatusRow = ({ thesis }: { thesis: Thesis }) => (
<Box
Expand Down Expand Up @@ -368,9 +372,11 @@ const ViewThesisFooter = (
const thesisId = rowSelectionModel[0] as unknown as string | undefined

const { t } = useTranslation()
const { user: currentUser } = useLoggedInUser()
const [eventLogOpen, setEventLogOpen] = useState(false)
const { thesis, isLoading: thesisLoading } = useSingleThesis(thesisId)
const { events } = useEvents({ thesisId })
const { mutateAsync: editThesis } = useEditThesisMutation()

return (
<>
Expand Down Expand Up @@ -416,8 +422,37 @@ const ViewThesisFooter = (
</Typography>
</Typography>

{thesis && (
{thesis && currentUser && (
<Box sx={{ display: 'flex', gap: 2 }}>
{Boolean(
thesis.status === THESIS_STATUSES.PLANNING &&
thesis.approvers?.length &&
thesis.approvers[0].id === currentUser?.id
) && (
<Button
variant="outlined"
sx={{
color: '#000',
backgroundColor: '#fcd34d',
fontSize: '12px',
height: 24,
px: 2,
borderRadius: '1rem',
fontWeight: 600,
}}
onClick={() =>
editThesis({
thesisId: thesis.id,
data: {
...thesis,
status: IN_PROGRESS_STATUS,
},
})
}
>
{t('approveButton')}
</Button>
)}
<Button
variant="outlined"
sx={{
Expand Down
1 change: 1 addition & 0 deletions src/client/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"supervisionsTable": "Supervisions",
"targetDateHeader": "Target date",
"editButton": "Edit",
"approveButton": "Approve",
"deleteButton": "Delete",
"cancelButton": "Cancel",
"submitButton": "Submit",
Expand Down
1 change: 1 addition & 0 deletions src/client/locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"supervisionPercentageHeader": "Ohjausprosentti",
"supervisionsTable": "Ohjaukset",
"targetDateHeader": "Tavoitepäivä",
"approveButton": "Hyväksy",
"editButton": "Muokkaa",
"deleteButton": "Poista",
"cancelButton": "Peruuta",
Expand Down

0 comments on commit 6eb5daf

Please sign in to comment.