|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import { FC, RefObject, useEffect, useRef, useState } from 'react'; |
4 | | -import { useLaunchStore } from '@gitroom/frontend/components/new-launch/store'; |
| 3 | +import { FC, RefObject, useCallback, useEffect, useRef, useState } from 'react'; |
| 4 | +import { |
| 5 | + SelectedIntegrations, |
| 6 | + useLaunchStore, |
| 7 | +} from '@gitroom/frontend/components/new-launch/store'; |
5 | 8 | import clsx from 'clsx'; |
6 | 9 | import Image from 'next/image'; |
7 | 10 | import { useShallow } from 'zustand/react/shallow'; |
8 | 11 | import { GlobalIcon } from '@gitroom/frontend/components/ui/icons'; |
9 | 12 | import { useT } from '@gitroom/react/translation/get.transation.service.client'; |
| 13 | +import { Integrations } from '@gitroom/frontend/components/launches/calendar.context'; |
| 14 | +import { |
| 15 | + useDecisionModal, |
| 16 | + useModals, |
| 17 | +} from '@gitroom/frontend/components/layout/new-modal'; |
10 | 18 |
|
11 | 19 | export function useHasScroll(ref: RefObject<HTMLElement>): boolean { |
12 | 20 | const [hasHorizontalScroll, setHasHorizontalScroll] = useState(false); |
@@ -43,20 +51,47 @@ export function useHasScroll(ref: RefObject<HTMLElement>): boolean { |
43 | 51 | } |
44 | 52 |
|
45 | 53 | export const SelectCurrent: FC = () => { |
46 | | - const { selectedIntegrations, current, setCurrent, locked, setHide } = |
47 | | - useLaunchStore( |
48 | | - useShallow((state) => ({ |
49 | | - selectedIntegrations: state.selectedIntegrations, |
50 | | - current: state.current, |
51 | | - setCurrent: state.setCurrent, |
52 | | - locked: state.locked, |
53 | | - setHide: state.setHide, |
54 | | - })) |
55 | | - ); |
| 54 | + const modals = useDecisionModal(); |
| 55 | + const { |
| 56 | + selectedIntegrations, |
| 57 | + current, |
| 58 | + setCurrent, |
| 59 | + locked, |
| 60 | + setHide, |
| 61 | + addOrRemoveSelectedIntegration, |
| 62 | + } = useLaunchStore( |
| 63 | + useShallow((state) => ({ |
| 64 | + selectedIntegrations: state.selectedIntegrations, |
| 65 | + addOrRemoveSelectedIntegration: state.addOrRemoveSelectedIntegration, |
| 66 | + current: state.current, |
| 67 | + setCurrent: state.setCurrent, |
| 68 | + locked: state.locked, |
| 69 | + setHide: state.setHide, |
| 70 | + })) |
| 71 | + ); |
56 | 72 |
|
57 | 73 | const contentRef = useRef<HTMLDivElement>(null); |
58 | 74 | const hasScroll = useHasScroll(contentRef); |
59 | 75 |
|
| 76 | + const removeSocial = useCallback( |
| 77 | + (sIntegration: Integrations) => async (e: any) => { |
| 78 | + e.stopPropagation(); |
| 79 | + e.preventDefault(); |
| 80 | + const open = await modals.open({ |
| 81 | + title: 'Remove Social Account', |
| 82 | + description: |
| 83 | + 'Are you sure you want to remove this social from scheduling?', |
| 84 | + }); |
| 85 | + |
| 86 | + if (!open) { |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + addOrRemoveSelectedIntegration(sIntegration, {}); |
| 91 | + }, |
| 92 | + [] |
| 93 | + ); |
| 94 | + |
60 | 95 | return ( |
61 | 96 | <> |
62 | 97 | <div className="select-none left-0 absolute w-full z-[100] px-[20px]"> |
@@ -97,6 +132,12 @@ export const SelectCurrent: FC = () => { |
97 | 132 | : 'border-transparent' |
98 | 133 | )} |
99 | 134 | > |
| 135 | + <div |
| 136 | + onClick={removeSocial(integration)} |
| 137 | + className="absolute justify-center items-center flex w-[8px] h-[8px] -top-[1px] -start-[3px] bg-red-500 rounded-full text-white text-[8px]" |
| 138 | + > |
| 139 | + X |
| 140 | + </div> |
100 | 141 | <IsGlobal id={integration.id} /> |
101 | 142 | <div |
102 | 143 | {...{ |
|
0 commit comments