'use client'; import { Button } from '@gitroom/react/form/button'; import clsx from 'clsx'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; import React, { createContext, FC, useCallback, useEffect, useMemo, useState, } from 'react'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import useSWR from 'swr'; import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component'; import './providers/heygen.provider'; import { thirdPartyList } from '@gitroom/frontend/components/third-parties/third-party.wrapper'; import { useLaunchStore } from '@gitroom/frontend/components/new-launch/store'; const ThirdPartyContext = createContext({ id: '', name: '', title: '', identifier: '', description: '', close: () => {}, onChange: (data: any) => {}, fields: [], data: [ { content: '', id: '', image: [ { id: '', path: '', }, ], }, ], }); export const useThirdParty = () => React.useContext(ThirdPartyContext); const EmptyComponent: FC = () => null; export const ThirdPartyPopup: FC<{ closeModal: () => void; thirdParties: any[]; onChange: (data: any) => void; allData: { content: string; id?: string; image?: Array<{ id: string; path: string; }>; }[]; }> = (props) => { const { closeModal, thirdParties, allData, onChange } = props; const [thirdParty, setThirdParty] = useState(null); const setActivateExitButton = useLaunchStore((e) => e.setActivateExitButton); useEffect(() => { setActivateExitButton(false); return () => { setActivateExitButton(true); }; }, []); const Component = useMemo(() => { if (!thirdParty) { return EmptyComponent; } return ( thirdPartyList.find((p) => p.identifier === thirdParty.identifier) ?.Component || EmptyComponent ); }, [thirdParty]); const close = useCallback(() => { setThirdParty(null); closeModal(); }, [setThirdParty, closeModal]); return (
e.stopPropagation()} >
{!thirdParty && (
{thirdParties.map((p: any) => (
{ setThirdParty(p); }} key={p.identifier} className="w-full h-full p-[20px] min-h-[100px] text-[14px] bg-third hover:bg-input transition-all text-textColor relative flex flex-col gap-[15px] cursor-pointer" >
{p.title}: {p.name}
{p.description}
))}
)} {thirdParty && ( <>
setThirdParty(null)} > {'<'} Back
)}
); }; export const ThirdPartyMedia: FC<{ onChange: (data: any) => void; allData: { content: string; id?: string; image?: Array<{ id: string; path: string; }>; }[]; }> = (props) => { const { allData, onChange } = props; const t = useT(); const fetch = useFetch(); const [popup, setPopup] = useState(false); const thirdParties = useCallback(async () => { return (await (await fetch('/third-party')).json()).filter( (f: any) => f.position === 'media' ); }, []); const { data, isLoading, mutate } = useSWR('third-party', thirdParties); if (isLoading || !data.length) { return null; } return ( <> {popup && ( setPopup(false)} allData={allData} onChange={onChange} /> )}
); };