Skip to content

Commit 9d98020

Browse files
committed
feat: move signature to global load and fix add a post
1 parent 4b5580b commit 9d98020

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

apps/frontend/src/components/launches/calendar.context.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const CalendarContext = createContext({
2828
currentMonth: dayjs().month(),
2929
customer: null as string | null,
3030
sets: [] as { name: string; id: string; content: string[] }[],
31+
signature: undefined as any,
3132
comments: [] as Array<{
3233
date: string;
3334
total: number;
@@ -144,11 +145,16 @@ export const CalendarWeekProvider: FC<{
144145
revalidateOnFocus: false,
145146
});
146147

148+
const defaultSign = useCallback(async () => {
149+
return await (await fetch('/signatures/default')).json();
150+
}, []);
151+
147152
const setList = useCallback(async () => {
148153
return (await fetch('/sets')).json();
149154
}, []);
150155

151156
const { data: sets, mutate } = useSWR('sets', setList);
157+
const { data: sign} = useSWR('default-sign', defaultSign);
152158

153159
const setFiltersWrapper = useCallback(
154160
(filters: {
@@ -211,6 +217,7 @@ export const CalendarWeekProvider: FC<{
211217
changeDate,
212218
comments,
213219
sets: sets || [],
220+
signature: sign,
214221
}}
215222
>
216223
{children}

apps/frontend/src/components/launches/calendar.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export const CalendarColumn: FC<{
337337
display,
338338
reloadCalendarView,
339339
sets,
340+
signature,
340341
} = useCalendar();
341342
const toaster = useToaster();
342343
const modal = useModals();
@@ -550,7 +551,6 @@ export const CalendarColumn: FC<{
550551
);
551552

552553
const addModal = useCallback(async () => {
553-
const signature = await (await fetch('/signatures/default')).json();
554554
const set: any = !sets.length
555555
? undefined
556556
: await new Promise((resolve) => {
@@ -597,7 +597,7 @@ export const CalendarColumn: FC<{
597597
...p,
598598
}))}
599599
mutate={reloadCalendarView}
600-
{...(signature?.id
600+
{...(signature?.id && !set
601601
? {
602602
onlyValues: [
603603
{
@@ -609,14 +609,13 @@ export const CalendarColumn: FC<{
609609
date={
610610
randomHour ? getDate.hour(Math.floor(Math.random() * 24)) : getDate
611611
}
612-
{...set?.content ? {set: JSON.parse(set.content)} : {}}
612+
{...(set?.content ? { set: JSON.parse(set.content) } : {})}
613613
reopenModal={() => ({})}
614614
/>
615615
),
616616
size: '80%',
617-
// title: `Adding posts for ${getDate.format('DD/MM/YYYY HH:mm')}`,
618617
});
619-
}, [integrations, getDate, sets]);
618+
}, [integrations, getDate, sets, signature]);
620619
const openStatistics = useCallback(
621620
(id: string) => () => {
622621
modal.openModal({
@@ -967,7 +966,7 @@ export const Statistics = () => {
967966
);
968967
};
969968

970-
const SetSelectionModal: FC<{
969+
export const SetSelectionModal: FC<{
971970
sets: any[];
972971
onSelect: (set: any) => void;
973972
onContinueWithoutSet: () => void;

apps/frontend/src/components/launches/new.post.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,47 @@ import dayjs from 'dayjs';
55
import { useCalendar } from '@gitroom/frontend/components/launches/calendar.context';
66
import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
77
import { useT } from '@gitroom/react/translation/get.transation.service.client';
8+
import { SetSelectionModal } from '@gitroom/frontend/components/launches/calendar';
9+
import { useSet } from '@gitroom/frontend/components/launches/set.context';
810
export const NewPost = () => {
911
const fetch = useFetch();
1012
const modal = useModals();
11-
const { integrations, reloadCalendarView } = useCalendar();
13+
const { integrations, reloadCalendarView, sets } = useCalendar();
1214
const t = useT();
1315

1416
const createAPost = useCallback(async () => {
1517
const date = (await (await fetch('/posts/find-slot')).json()).date;
18+
19+
const set: any = !sets.length
20+
? undefined
21+
: await new Promise((resolve) => {
22+
modal.openModal({
23+
title: t('select_set', 'Select a Set'),
24+
closeOnClickOutside: true,
25+
closeOnEscape: true,
26+
withCloseButton: true,
27+
onClose: () => resolve('exit'),
28+
classNames: {
29+
modal: 'bg-secondary text-textColor',
30+
},
31+
children: (
32+
<SetSelectionModal
33+
sets={sets}
34+
onSelect={(selectedSet) => {
35+
resolve(selectedSet);
36+
modal.closeAll();
37+
}}
38+
onContinueWithoutSet={() => {
39+
resolve(undefined);
40+
modal.closeAll();
41+
}}
42+
/>
43+
),
44+
});
45+
});
46+
47+
if (set === 'exit') return;
48+
1649
modal.openModal({
1750
closeOnClickOutside: false,
1851
closeOnEscape: false,
@@ -25,6 +58,7 @@ export const NewPost = () => {
2558
allIntegrations={integrations.map((p) => ({
2659
...p,
2760
}))}
61+
{...(set?.content ? { set: JSON.parse(set.content) } : {})}
2862
reopenModal={createAPost}
2963
mutate={reloadCalendarView}
3064
integrations={integrations}
@@ -34,7 +68,7 @@ export const NewPost = () => {
3468
size: '80%',
3569
title: ``,
3670
});
37-
}, [integrations]);
71+
}, [integrations, sets]);
3872
return (
3973
<button
4074
onClick={createAPost}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"prisma-reset": "cd ./libraries/nestjs-libraries/src/database/prisma && pnpm dlx prisma db push --force-reset && npx prisma db push",
4141
"docker-build": "./var/docker/docker-build.sh",
4242
"docker-create": "./var/docker/docker-create.sh",
43-
"postinstall": "npm run update-plugins && npm run prisma-generate",
43+
"postinstall": "pnpm run update-plugins && pnpm run prisma-generate",
4444
"test": "jest --coverage --detectOpenHandles --reporters=default --reporters=jest-junit"
4545
},
4646
"dependencies": {

0 commit comments

Comments
 (0)