Add commitee initials in event title
This commit is contained in:
parent
46aa2c0af4
commit
7539a6a9fb
@ -1,4 +1,4 @@
|
||||
import { Calendar, Views } from 'react-big-calendar'
|
||||
import { Calendar, Views, View } from 'react-big-calendar'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useMutation, useQuery } from 'react-query'
|
||||
import {
|
||||
@ -56,7 +56,7 @@ const Schedule = () => {
|
||||
id: number
|
||||
resource: any
|
||||
}>()
|
||||
const [view, setView] = useState(Views.MONTH)
|
||||
const [view, setView] = useState<View>(Views.WEEK)
|
||||
const onView = useCallback((newView: any) => setView(newView), [setView])
|
||||
|
||||
const [isModalOpen, setIsModalOpen] = useState(false)
|
||||
@ -93,7 +93,7 @@ const Schedule = () => {
|
||||
},
|
||||
)
|
||||
|
||||
const { refetch, isFetching } = useQuery(
|
||||
const { refetch } = useQuery(
|
||||
['schedules'],
|
||||
() => getTermsOfDefences(Number(id)),
|
||||
{
|
||||
@ -101,17 +101,28 @@ const Schedule = () => {
|
||||
if (data) {
|
||||
setEvents(
|
||||
data.data.term_of_defences.map(
|
||||
({
|
||||
id,
|
||||
start_date,
|
||||
end_date,
|
||||
title = 'Obrona',
|
||||
members_of_committee,
|
||||
group,
|
||||
}) => {
|
||||
({ id, start_date, end_date, members_of_committee, group }) => {
|
||||
let initials = ''
|
||||
let title = ''
|
||||
members_of_committee.forEach((member) => {
|
||||
initials +=
|
||||
`${member.first_name} ${member.last_name}`
|
||||
.split(' ')
|
||||
.map((n) => n[0])
|
||||
.join('') + ' '
|
||||
})
|
||||
if (group?.name && initials) {
|
||||
title = `${group.name} | ${initials}`
|
||||
} else if (group?.name) {
|
||||
title = group.name
|
||||
} else if (initials) {
|
||||
title = `- | ${initials}`
|
||||
} else {
|
||||
title = '-'
|
||||
}
|
||||
return {
|
||||
id,
|
||||
title: `${group?.name ?? '-'}`,
|
||||
title: title,
|
||||
start: new Date(start_date),
|
||||
end: new Date(end_date),
|
||||
resource: {
|
||||
@ -127,31 +138,6 @@ const Schedule = () => {
|
||||
},
|
||||
)
|
||||
|
||||
const { refetch: refetchWithGroups } = useQuery(
|
||||
['schedules_groups'],
|
||||
() => getTermsOfDefencesWithGroups(Number(id)),
|
||||
{
|
||||
onSettled: (data) => {
|
||||
data?.data.term_of_defences.forEach((term) => {
|
||||
const index = events.findIndex((event) => event.id === term.id)
|
||||
if (index !== -1) {
|
||||
const eventsCopy = [...events]
|
||||
eventsCopy[index] = {
|
||||
...eventsCopy[index],
|
||||
title: term.group.name,
|
||||
resource: {
|
||||
...eventsCopy[index].resource,
|
||||
group: term.group,
|
||||
},
|
||||
}
|
||||
setEvents(eventsCopy)
|
||||
}
|
||||
})
|
||||
},
|
||||
enabled: !isFetching,
|
||||
},
|
||||
)
|
||||
|
||||
const { mutateAsync: mutateCreateEvent } = useMutation(
|
||||
['createEvent'],
|
||||
(data: {
|
||||
@ -213,7 +199,8 @@ const Schedule = () => {
|
||||
setIsModalOpen(false)
|
||||
}
|
||||
const onSubmit = async (data: any) => {
|
||||
if (selectedDate && view === Views.MONTH) {
|
||||
// if (selectedDate && view === Views.MONTH) {
|
||||
if (selectedDate) {
|
||||
const from = data.from.split(':')
|
||||
const to = data.to.split(':')
|
||||
await mutateCreateEvent({
|
||||
@ -229,7 +216,6 @@ const Schedule = () => {
|
||||
project_supervisors: data?.project_supervisors,
|
||||
})
|
||||
refetch()
|
||||
refetchWithGroups()
|
||||
reset()
|
||||
closeModal()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user