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 { useCallback, useEffect, useState } from 'react'
|
||||||
import { useMutation, useQuery } from 'react-query'
|
import { useMutation, useQuery } from 'react-query'
|
||||||
import {
|
import {
|
||||||
@ -56,7 +56,7 @@ const Schedule = () => {
|
|||||||
id: number
|
id: number
|
||||||
resource: any
|
resource: any
|
||||||
}>()
|
}>()
|
||||||
const [view, setView] = useState(Views.MONTH)
|
const [view, setView] = useState<View>(Views.WEEK)
|
||||||
const onView = useCallback((newView: any) => setView(newView), [setView])
|
const onView = useCallback((newView: any) => setView(newView), [setView])
|
||||||
|
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false)
|
const [isModalOpen, setIsModalOpen] = useState(false)
|
||||||
@ -93,7 +93,7 @@ const Schedule = () => {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const { refetch, isFetching } = useQuery(
|
const { refetch } = useQuery(
|
||||||
['schedules'],
|
['schedules'],
|
||||||
() => getTermsOfDefences(Number(id)),
|
() => getTermsOfDefences(Number(id)),
|
||||||
{
|
{
|
||||||
@ -101,17 +101,28 @@ const Schedule = () => {
|
|||||||
if (data) {
|
if (data) {
|
||||||
setEvents(
|
setEvents(
|
||||||
data.data.term_of_defences.map(
|
data.data.term_of_defences.map(
|
||||||
({
|
({ id, start_date, end_date, members_of_committee, group }) => {
|
||||||
id,
|
let initials = ''
|
||||||
start_date,
|
let title = ''
|
||||||
end_date,
|
members_of_committee.forEach((member) => {
|
||||||
title = 'Obrona',
|
initials +=
|
||||||
members_of_committee,
|
`${member.first_name} ${member.last_name}`
|
||||||
group,
|
.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 {
|
return {
|
||||||
id,
|
id,
|
||||||
title: `${group?.name ?? '-'}`,
|
title: title,
|
||||||
start: new Date(start_date),
|
start: new Date(start_date),
|
||||||
end: new Date(end_date),
|
end: new Date(end_date),
|
||||||
resource: {
|
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(
|
const { mutateAsync: mutateCreateEvent } = useMutation(
|
||||||
['createEvent'],
|
['createEvent'],
|
||||||
(data: {
|
(data: {
|
||||||
@ -213,7 +199,8 @@ const Schedule = () => {
|
|||||||
setIsModalOpen(false)
|
setIsModalOpen(false)
|
||||||
}
|
}
|
||||||
const onSubmit = async (data: any) => {
|
const onSubmit = async (data: any) => {
|
||||||
if (selectedDate && view === Views.MONTH) {
|
// if (selectedDate && view === Views.MONTH) {
|
||||||
|
if (selectedDate) {
|
||||||
const from = data.from.split(':')
|
const from = data.from.split(':')
|
||||||
const to = data.to.split(':')
|
const to = data.to.split(':')
|
||||||
await mutateCreateEvent({
|
await mutateCreateEvent({
|
||||||
@ -229,7 +216,6 @@ const Schedule = () => {
|
|||||||
project_supervisors: data?.project_supervisors,
|
project_supervisors: data?.project_supervisors,
|
||||||
})
|
})
|
||||||
refetch()
|
refetch()
|
||||||
refetchWithGroups()
|
|
||||||
reset()
|
reset()
|
||||||
closeModal()
|
closeModal()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user