diff --git a/apps/frontend/src/components/launches/calendar.context.tsx b/apps/frontend/src/components/launches/calendar.context.tsx index f054d22b..785fdac5 100644 --- a/apps/frontend/src/components/launches/calendar.context.tsx +++ b/apps/frontend/src/components/launches/calendar.context.tsx @@ -28,6 +28,7 @@ export const CalendarContext = createContext({ currentMonth: dayjs().month(), customer: null as string | null, sets: [] as { name: string; id: string; content: string[] }[], + signature: undefined as any, comments: [] as Array<{ date: string; total: number; @@ -144,11 +145,16 @@ export const CalendarWeekProvider: FC<{ revalidateOnFocus: false, }); + const defaultSign = useCallback(async () => { + return await (await fetch('/signatures/default')).json(); + }, []); + const setList = useCallback(async () => { return (await fetch('/sets')).json(); }, []); const { data: sets, mutate } = useSWR('sets', setList); + const { data: sign} = useSWR('default-sign', defaultSign); const setFiltersWrapper = useCallback( (filters: { @@ -211,6 +217,7 @@ export const CalendarWeekProvider: FC<{ changeDate, comments, sets: sets || [], + signature: sign, }} > {children} diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsx index 3b40cf8e..434cc503 100644 --- a/apps/frontend/src/components/launches/calendar.tsx +++ b/apps/frontend/src/components/launches/calendar.tsx @@ -337,6 +337,7 @@ export const CalendarColumn: FC<{ display, reloadCalendarView, sets, + signature, } = useCalendar(); const toaster = useToaster(); const modal = useModals(); @@ -550,7 +551,6 @@ export const CalendarColumn: FC<{ ); const addModal = useCallback(async () => { - const signature = await (await fetch('/signatures/default')).json(); const set: any = !sets.length ? undefined : await new Promise((resolve) => { @@ -597,7 +597,7 @@ export const CalendarColumn: FC<{ ...p, }))} mutate={reloadCalendarView} - {...(signature?.id + {...(signature?.id && !set ? { onlyValues: [ { @@ -609,14 +609,13 @@ export const CalendarColumn: FC<{ date={ randomHour ? getDate.hour(Math.floor(Math.random() * 24)) : getDate } - {...set?.content ? {set: JSON.parse(set.content)} : {}} + {...(set?.content ? { set: JSON.parse(set.content) } : {})} reopenModal={() => ({})} /> ), size: '80%', - // title: `Adding posts for ${getDate.format('DD/MM/YYYY HH:mm')}`, }); - }, [integrations, getDate, sets]); + }, [integrations, getDate, sets, signature]); const openStatistics = useCallback( (id: string) => () => { modal.openModal({ @@ -967,7 +966,7 @@ export const Statistics = () => { ); }; -const SetSelectionModal: FC<{ +export const SetSelectionModal: FC<{ sets: any[]; onSelect: (set: any) => void; onContinueWithoutSet: () => void; diff --git a/apps/frontend/src/components/launches/new.post.tsx b/apps/frontend/src/components/launches/new.post.tsx index 5920be6b..f1cb8c8d 100644 --- a/apps/frontend/src/components/launches/new.post.tsx +++ b/apps/frontend/src/components/launches/new.post.tsx @@ -5,14 +5,47 @@ import dayjs from 'dayjs'; import { useCalendar } from '@gitroom/frontend/components/launches/calendar.context'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; +import { SetSelectionModal } from '@gitroom/frontend/components/launches/calendar'; +import { useSet } from '@gitroom/frontend/components/launches/set.context'; export const NewPost = () => { const fetch = useFetch(); const modal = useModals(); - const { integrations, reloadCalendarView } = useCalendar(); + const { integrations, reloadCalendarView, sets } = useCalendar(); const t = useT(); const createAPost = useCallback(async () => { const date = (await (await fetch('/posts/find-slot')).json()).date; + + const set: any = !sets.length + ? undefined + : await new Promise((resolve) => { + modal.openModal({ + title: t('select_set', 'Select a Set'), + closeOnClickOutside: true, + closeOnEscape: true, + withCloseButton: true, + onClose: () => resolve('exit'), + classNames: { + modal: 'bg-secondary text-textColor', + }, + children: ( + { + resolve(selectedSet); + modal.closeAll(); + }} + onContinueWithoutSet={() => { + resolve(undefined); + modal.closeAll(); + }} + /> + ), + }); + }); + + if (set === 'exit') return; + modal.openModal({ closeOnClickOutside: false, closeOnEscape: false, @@ -25,6 +58,7 @@ export const NewPost = () => { allIntegrations={integrations.map((p) => ({ ...p, }))} + {...(set?.content ? { set: JSON.parse(set.content) } : {})} reopenModal={createAPost} mutate={reloadCalendarView} integrations={integrations} @@ -34,7 +68,7 @@ export const NewPost = () => { size: '80%', title: ``, }); - }, [integrations]); + }, [integrations, sets]); return (