@airporting/integrations-app 0.4.33 → 0.4.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ export declare function useSynchroJobDeleteMutation(): import("@tanstack/react-query").UseMutationResult<any, Error, {
2
+ id: number;
3
+ jobId: number;
4
+ }, unknown>;
@@ -0,0 +1,5 @@
1
+ export declare function useSynchroJobToggleMutation(): import("@tanstack/react-query").UseMutationResult<any, Error, {
2
+ id: number;
3
+ jobId: number;
4
+ active: boolean;
5
+ }, unknown>;
@@ -24,6 +24,8 @@ export type RecipeJob = {
24
24
  lastTask?: RecipeTask;
25
25
  connector_from?: ConnectorInfo;
26
26
  connector_to?: ConnectorInfo;
27
+ allow_delete?: boolean;
28
+ allow_disable?: boolean;
27
29
  };
28
30
  export type RecipeSchedule = {
29
31
  id: number;
@@ -39,6 +41,10 @@ export type ConnectorInfo = {
39
41
  name: string;
40
42
  codename: string;
41
43
  logo_key: string | null;
44
+ type?: {
45
+ codename: string;
46
+ name: string;
47
+ } | null;
42
48
  };
43
49
  export type Recipe = {
44
50
  id: number;
@@ -7,4 +7,4 @@
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */var REACT_ELEMENT_TYPE=Symbol.for("react.transitional.element"),REACT_FRAGMENT_TYPE=Symbol.for("react.fragment");function jsxProd(type,config,maybeKey){var key=null;void 0!==maybeKey&&(key=""+maybeKey);void 0!==config.key&&(key=""+config.key);if("key"in config){maybeKey={};for(var propName in config)"key"!==propName&&(maybeKey[propName]=config[propName])}else maybeKey=config;config=maybeKey.ref;return{$$typeof:REACT_ELEMENT_TYPE,type:type,key:key,ref:void 0!==config?config:null,props:maybeKey}}exports.Fragment=REACT_FRAGMENT_TYPE;exports.jsx=jsxProd;exports.jsxs=jsxProd},4848:function(module,__unused_webpack_exports,__webpack_require__){module.exports=__webpack_require__(9698)},8291:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>Connectors});var jsx_runtime=__webpack_require__(4848);var index_js_=__webpack_require__(8556);var index_mjs_=__webpack_require__(2773);var modern_index_js_=__webpack_require__(7714);var IntegrationsApi=__webpack_require__(6699);const AppConfigCtx=/*#__PURE__*/(0,index_js_.createContext)(null);const AppConfigProvider=AppConfigCtx.Provider;function useAppConfig(){const config=(0,index_js_.useContext)(AppConfigCtx);if(!config)throw new Error("Called `useAppConfig` outside a `<AppConfigProvider />`");return config}function useApi(){const config=useAppConfig();const client=new IntegrationsApi.Qq({baseUrl:config.api.replace(/\/$/,""),baseApiParams:{headers:{Authorization:config.token?`Bearer ${config.token}`:"",From:config.owner}}});return new IntegrationsApi.qx(client)}function useStatsQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","stats",config.company],queryFn:async()=>await api.connectors.getStatsConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}function useConnectorsListQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","list",config.company],queryFn:async()=>await api.connectors.getConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}var connector_bubble=__webpack_require__(4184);var tabler_icons_react_mjs_=__webpack_require__(5200);var esm_index_mjs_=__webpack_require__(4931);function useConnectorDeleteMutation(){const api=useApi();const config=useAppConfig();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async connector=>{const res=await api.connectors.deleteConnectorV1({cid:config.company,connector});return res.data},onSuccess:()=>{queryClient.invalidateQueries({queryKey:["connectors","list",config.company]});queryClient.invalidateQueries({queryKey:["connectors","list","ill",config.company]});queryClient.invalidateQueries({queryKey:["connectors","catalog",config.company]});queryClient.invalidateQueries({queryKey:["connectors","stats",config.company]});esm_index_mjs_.notifications.show({color:"green",title:"Connecteur supprim\xe9",message:"Vous pouvez le r\xe9ajouter depuis le catalogue."})},onError:error=>{console.error(error);esm_index_mjs_.notifications.show({color:"red",title:"Suppression \xe9chou\xe9e",message:"R\xe9essayez dans un instant."})}})}var modals_esm_index_mjs_=__webpack_require__(4403);function isDeleteConfirmInput(input){return"DELETE"===input}function DeleteActiveBody({name,onConfirm}){const[input,setInput]=(0,index_js_.useState)("");const isMatch=isDeleteConfirmInput(input);const handleConfirm=()=>{if(!isMatch)return;onConfirm();modals_esm_index_mjs_.modals.closeAll()};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",children:["Le connecteur ",/*#__PURE__*/(0,jsx_runtime.jsx)("strong",{children:name})," est actuellement actif. Sa suppression arr\xeatera la synchronisation et le retirera de la liste. Vous pourrez le r\xe9ajouter depuis le catalogue plus tard."]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",children:["Pour confirmer, tapez ",/*#__PURE__*/(0,jsx_runtime.jsx)("strong",{children:"DELETE"})," ci-dessous."]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{value:input,onChange:e=>setInput(e.currentTarget.value),placeholder:"DELETE",autoFocus:true,onKeyDown:e=>{if("Enter"===e.key)handleConfirm()}}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>modals_esm_index_mjs_.modals.closeAll(),children:"Annuler"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{color:"red",disabled:!isMatch,onClick:handleConfirm,children:"Supprimer"})]})]})}function openDeleteActiveConnectorModal(name,onConfirm){modals_esm_index_mjs_.modals.open({title:"Supprimer ce connecteur ?",centered:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(DeleteActiveBody,{name:name,onConfirm:onConfirm})})}function ConnectorMenu({connectorId,connectorName,isActive}){const{mutate,isPending}=useConnectorDeleteMutation();const handleDelete=()=>{if(isActive)openDeleteActiveConnectorModal(connectorName,()=>mutate(connectorId));else mutate(connectorId)};const stopBubble=e=>{e.stopPropagation();e.preventDefault()};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu,{position:"bottom-end",withinPortal:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Target,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{variant:"subtle",color:"gray","aria-label":"Actions du connecteur",onClick:stopBubble,children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconDots,{size:18})})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Dropdown,{onClick:stopBubble,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{color:"red",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTrash,{size:16}),onClick:handleDelete,disabled:isPending,children:"Supprimer"})})]})}function ListOkComponent(){const config=useAppConfig();const listResultRes=useConnectorsListQuery();const listResult=listResultRes.data;return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:2,children:"Tous vos connecteurs en marche"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",style:{alignItems:"stretch"},children:listResult?.list?.map((connector,idx)=>connector?.main_connectorlist?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Card,{pos:"relative",style:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Anchor,{underline:"never",href:`/company/${config.company}/integrations/${connector.id}/connector`,children:/*#__PURE__*/(0,jsx_runtime.jsx)(connector_bubble.q,{connector:connector})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{pos:"absolute",top:8,right:8,children:/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorMenu,{connectorId:connector.id,connectorName:connector.name,isActive:true})})]},idx):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{radius:"md",animate:true},idx))})]})}function useConnectorsIllListQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","list","ill",config.company],queryFn:async()=>await api.connectors.getIllConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}function ListIllComponent(){const config=useAppConfig();const listResultRes=useConnectorsIllListQuery();const listResult=listResultRes.data;return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:2,children:"Tous vos connecteurs \xe0 configurer"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",style:{alignItems:"stretch"},children:listResult?.list?.map((connector,idx)=>connector?.main_connectorlist?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Card,{pos:"relative",style:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Anchor,{underline:"never",href:`/company/${config.company}/integrations/${connector.id}/connector`,children:/*#__PURE__*/(0,jsx_runtime.jsx)(connector_bubble.q,{connector:connector})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{pos:"absolute",top:8,right:8,children:/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorMenu,{connectorId:connector.id,connectorName:connector.name,isActive:false})})]},idx):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{radius:"md",animate:true},idx))})]})}function useConnectorAddMutation(){const api=useApi();const config=useAppConfig();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async connector_id=>{const res=await api.connectors.addConnectorV1({cid:config.company},{connector_id});return res.data},onSuccess:()=>{queryClient.invalidateQueries({queryKey:["connectors","catalog",config.company]});queryClient.invalidateQueries({queryKey:["connectors","list",config.company]});queryClient.invalidateQueries({queryKey:["connectors","list","ill",config.company]});queryClient.invalidateQueries({queryKey:["connectors","stats",config.company]})}})}function useConnectorCatalogQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","catalog",config.company],queryFn:async()=>await api.connectors.getCatalogConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}function normalize(value){return(value??"").toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,"")}function getBaseName(name){return name.replace(/\s+via\s+.+$/i,"").trim()}function getMethodSuffix(name,baseName){return name.length>baseName.length?name.slice(baseName.length).trim():name}function getLogoUrl(logoKey,codename){return logoKey?`https://img.logo.dev/${logoKey}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${codename}.png`}function GroupCard({group,pending}){const{colorScheme}=(0,index_mjs_.useMantineColorScheme)();const bg="dark"===colorScheme?"white":"dark";const first=group.items[0];const logoUrl=getLogoUrl(group.logoKey,first.codename);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",children:[pending?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Loader,{size:64}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:logoUrl,size:64,radius:"md",bg:bg,color:"dark"===colorScheme?"black":"white",p:18}),group.items.length>1&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Badge,{variant:"light",color:"blue",children:[group.items.length," m\xe9thodes"]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",order:3,children:group.baseName}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"lg",lineClamp:3,children:first.description_fr})]})})}function MethodChoiceCard({item,baseName,pending,disabled,onClick}){const suffix=getMethodSuffix(item.name,baseName);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{style:{cursor:disabled?"wait":"pointer",opacity:disabled&&!pending?.5:1},onClick:()=>{if(!disabled)onClick()},children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"center",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,style:{flex:1},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:600,children:suffix||item.name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{variant:"light",color:"gray",children:item.sharing_method})]}),item.description_fr&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",lineClamp:2,children:item.description_fr})]}),pending&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Loader,{size:"sm"})]})})}function ListCatalogComponent(){const config=useAppConfig();const result=useConnectorCatalogQuery();const list=result.data?.list;const[searchValue,setSearchValue]=(0,index_js_.useState)("");const[pendingId,setPendingId]=(0,index_js_.useState)(null);const[selectedGroup,setSelectedGroup]=(0,index_js_.useState)(null);const mutation=useConnectorAddMutation();const filtered=(0,index_js_.useMemo)(()=>{if(!list)return;const q=normalize(searchValue);if(!q)return list;return list.filter(item=>normalize(`${item.name} ${item.description_fr??""}`).includes(q))},[list,searchValue]);const sections=(0,index_js_.useMemo)(()=>{if(!filtered)return;const groups=new Map;for(const item of filtered){const baseName=getBaseName(item.name);const groupKey=`${item.logo_key??item.codename}::${baseName}`;if(!groups.has(groupKey))groups.set(groupKey,{groupKey,baseName,type:item.type,logoKey:item.logo_key,items:[]});groups.get(groupKey).items.push(item)}const byCategory=new Map;for(const group of groups.values()){const k=group.type.codename;if(!byCategory.has(k))byCategory.set(k,{type:group.type,groups:[]});byCategory.get(k).groups.push(group)}return Array.from(byCategory.values())},[filtered]);const triggerAdd=id=>{setPendingId(id);mutation.mutate(id,{onSuccess:data=>{window.location.href=`/company/${config.company}/integrations/${data.id}/connector`},onError:()=>{setPendingId(null)}})};const handleGroupClick=group=>{if(mutation.isPending)return;if(1===group.items.length)triggerAdd(group.items[0].id);else setSelectedGroup(group)};const handleCloseModal=()=>{if(mutation.isPending)return;setSelectedGroup(null);setPendingId(null)};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:2,children:"Connecteurs disponibles"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{placeholder:"Rechercher un connecteur...",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconSearch,{size:16}),value:searchValue,onChange:e=>setSearchValue(e.currentTarget.value),size:"md"}),sections?sections.map(section=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:3,children:section.type.name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",style:{alignItems:"stretch"},children:section.groups.map(group=>{const isSinglePending=1===group.items.length&&pendingId===group.items[0].id;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{style:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between",cursor:mutation.isPending?"wait":"pointer",opacity:mutation.isPending&&!isSinglePending?.5:1},onClick:()=>handleGroupClick(group),children:/*#__PURE__*/(0,jsx_runtime.jsx)(GroupCard,{group:group,pending:isSinglePending})},group.groupKey)})})]},section.type.codename)):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",children:Array.from({length:8}).map((_,idx)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{height:180,radius:"md",animate:true},idx))}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:null!==selectedGroup,onClose:handleCloseModal,title:selectedGroup?.baseName??"",size:"lg",children:selectedGroup&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"Choisir une m\xe9thode de connexion :"}),selectedGroup.items.map(item=>/*#__PURE__*/(0,jsx_runtime.jsx)(MethodChoiceCard,{item:item,baseName:selectedGroup.baseName,pending:pendingId===item.id,disabled:mutation.isPending,onClick:()=>triggerAdd(item.id)},item.id))]})})]})}var dist_index_js_=__webpack_require__(6584);function ConnectorsApp(){const tab=(0,dist_index_js_.useRxState)(new URL(location.href).searchParams.get("tab")??"active");const statsResultRes=useStatsQuery();const statsResult=statsResultRes.data;const[tabValue,setTabValue]=(0,index_js_.useState)(tab.value??"active");(0,index_js_.useEffect)(()=>{tab.dispatch(tabValue)},[tabValue]);return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{py:16,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:1,children:"Nos connecteurs"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{w:"fit-content",mb:0,c:"dimmed",fz:"h5",children:"Synchronisez vos comptes bancaires et outils comptables facilement."})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{py:16,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SegmentedControl,{value:tabValue,onChange:setTabValue,radius:"md",size:"xl",data:[{label:`Connecteurs actifs(${statsResult?.ok?statsResult.ok:0})`,value:"active"},{label:`Connecteurs \xe0 configurer (${statsResult?.ill?statsResult.ill:0})`,value:"ill"},{label:`Connecteurs en maintenance (${statsResult?.maintenance?statsResult.maintenance:0})`,value:"maintenance"},{label:"Tous les connecteurs",value:"all"}]})}),"active"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)(ListOkComponent,{}),"ill"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)(ListIllComponent,{}),"maintenance"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)("p",{children:"page under progress"}),"all"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)(ListCatalogComponent,{})]})}var dist_esm_index_mjs_=__webpack_require__(4449);const theme=(0,index_mjs_.createTheme)((0,dist_esm_index_mjs_.assign)(dist_index_js_.theme,{components:{}}));const cssVarResolver=x=>(0,dist_esm_index_mjs_.assign)(dist_index_js_.cssVarResolver(x),{dark:{},light:{},variables:{}});function Providers(props){const{children,config,mantine,tanstack}=props;return/*#__PURE__*/(0,jsx_runtime.jsx)(AppConfigProvider,{value:config,children:/*#__PURE__*/(0,jsx_runtime.jsx)(modern_index_js_.QueryClientProvider,{client:tanstack?.queryClient??new modern_index_js_.QueryClient,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.MantineProvider,{theme:theme,cssVariablesResolver:cssVarResolver,defaultColorScheme:mantine?.defaultColorScheme,forceColorScheme:mantine?.forceColorScheme,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(modals_esm_index_mjs_.ModalsProvider,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(esm_index_mjs_.Notifications,{}),children]})})})})}function Connectors(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(Providers,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorsApp,{})})})}},4184:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{q:()=>ConnectorBubble});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(4848);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(2773);function ConnectorBubble({connector}){const{colorScheme}=(0,_mantine_core__WEBPACK_IMPORTED_MODULE_1__.useMantineColorScheme)();const bg="dark"===colorScheme?"white":"dark";const logoUrl=connector.main_connectorlist.logo_key?`https://img.logo.dev/${connector.main_connectorlist.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${connector.main_connectorlist.codename}.png`;return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Card,{children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Stack,{children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Avatar,{src:logoUrl,size:64,radius:"md",bg:bg,color:"dark"===colorScheme?"black":"white",p:18}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Title,{w:"fit-content",order:3,children:connector.name}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Text,{c:"dimmed",size:"lg",lineClamp:3,children:connector.main_connectorlist.description_fr})]})})}},6699:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{Qq:()=>HttpClient,qx:()=>IntegrationsApi});class HttpClient{baseUrl="";securityData=null;securityWorker;abortControllers=new Map;customFetch=(...fetchParams)=>fetch(...fetchParams);baseApiParams={credentials:"same-origin",headers:{},redirect:"follow",referrerPolicy:"no-referrer"};constructor(apiConfig={}){Object.assign(this,apiConfig)}setSecurityData=data=>{this.securityData=data};encodeQueryParam(key,value){const encodedKey=encodeURIComponent(key);return`${encodedKey}=${encodeURIComponent("number"==typeof value?value:`${value}`)}`}addQueryParam(query,key){return this.encodeQueryParam(key,query[key])}addArrayQueryParam(query,key){const value=query[key];return value.map(v=>this.encodeQueryParam(key,v)).join("&")}toQueryString(rawQuery){const query=rawQuery||{};const keys=Object.keys(query).filter(key=>void 0!==query[key]);return keys.map(key=>Array.isArray(query[key])?this.addArrayQueryParam(query,key):this.addQueryParam(query,key)).join("&")}addQueryParams(rawQuery){const queryString=this.toQueryString(rawQuery);return queryString?`?${queryString}`:""}contentFormatters={["application/json"]:input=>null!==input&&("object"==typeof input||"string"==typeof input)?JSON.stringify(input):input,["application/vnd.api+json"]:input=>null!==input&&("object"==typeof input||"string"==typeof input)?JSON.stringify(input):input,["text/plain"]:input=>null!==input&&"string"!=typeof input?JSON.stringify(input):input,["multipart/form-data"]:input=>{if(input instanceof FormData)return input;return Object.keys(input||{}).reduce((formData,key)=>{const property=input[key];formData.append(key,property instanceof Blob?property:"object"==typeof property&&null!==property?JSON.stringify(property):`${property}`);return formData},new FormData)},["application/x-www-form-urlencoded"]:input=>this.toQueryString(input)};mergeRequestParams(params1,params2){return{...this.baseApiParams,...params1,...params2||{},headers:{...this.baseApiParams.headers||{},...params1.headers||{},...params2&&params2.headers||{}}}}createAbortSignal=cancelToken=>{if(this.abortControllers.has(cancelToken)){const abortController=this.abortControllers.get(cancelToken);if(abortController)return abortController.signal;return}const abortController=new AbortController;this.abortControllers.set(cancelToken,abortController);return abortController.signal};abortRequest=cancelToken=>{const abortController=this.abortControllers.get(cancelToken);if(abortController){abortController.abort();this.abortControllers.delete(cancelToken)}};request=async({body,secure,path,type,query,format,baseUrl,cancelToken,...params})=>{const secureParams=("boolean"==typeof secure?secure:this.baseApiParams.secure)&&this.securityWorker&&await this.securityWorker(this.securityData)||{};const requestParams=this.mergeRequestParams(params,secureParams);const queryString=query&&this.toQueryString(query);const payloadFormatter=this.contentFormatters[type||"application/json"];const responseFormat=format||requestParams.format;return this.customFetch(`${baseUrl||this.baseUrl||""}${path}${queryString?`?${queryString}`:""}`,{...requestParams,headers:{...requestParams.headers||{},...type&&"multipart/form-data"!==type?{"Content-Type":type}:{}},signal:(cancelToken?this.createAbortSignal(cancelToken):requestParams.signal)||null,body:null==body?null:payloadFormatter(body)}).then(async response=>{const r=response;r.data=null;r.error=null;const responseToParse=responseFormat?response.clone():response;const data=responseFormat?await responseToParse[responseFormat]().then(data=>{if(r.ok)r.data=data;else r.error=data;return r}).catch(e=>{r.error=e;return r}):r;if(cancelToken)this.abortControllers.delete(cancelToken);if(!response.ok)throw data;return data})}}class IntegrationsApi{http;constructor(http){this.http=http}status=(params={})=>this.http.request({path:"/status",method:"GET",...params});connectors={getStatsConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/stats`,method:"GET",secure:true,format:"json",...params}),getConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/ok`,method:"GET",secure:true,format:"json",...params}),getIllConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/ill`,method:"GET",secure:true,format:"json",...params}),getCatalogConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/catalog`,method:"GET",secure:true,format:"json",...params}),addConnectorV1:({cid,...query},data,params={})=>this.http.request({path:`/v1/connectors/${cid}/add`,method:"POST",body:data,secure:true,type:"application/json",format:"json",...params}),getConnectorConfigV1:({connector,cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/config/${connector}`,method:"GET",format:"json",...params}),getConnectorSingleV1:({connector,cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/single/${connector}`,method:"GET",format:"json",...params}),putConnectorDataV1:({connector,cid,...query},data,params={})=>this.http.request({path:`/v1/connectors/${cid}/data/${connector}`,method:"PUT",body:data,type:"application/json",format:"json",...params}),deleteConnectorV1:({connector,cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/${connector}`,method:"DELETE",secure:true,...params})}}}}]);
10
+ */var REACT_ELEMENT_TYPE=Symbol.for("react.transitional.element"),REACT_FRAGMENT_TYPE=Symbol.for("react.fragment");function jsxProd(type,config,maybeKey){var key=null;void 0!==maybeKey&&(key=""+maybeKey);void 0!==config.key&&(key=""+config.key);if("key"in config){maybeKey={};for(var propName in config)"key"!==propName&&(maybeKey[propName]=config[propName])}else maybeKey=config;config=maybeKey.ref;return{$$typeof:REACT_ELEMENT_TYPE,type:type,key:key,ref:void 0!==config?config:null,props:maybeKey}}exports.Fragment=REACT_FRAGMENT_TYPE;exports.jsx=jsxProd;exports.jsxs=jsxProd},4848:function(module,__unused_webpack_exports,__webpack_require__){module.exports=__webpack_require__(9698)},8291:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>Connectors});var jsx_runtime=__webpack_require__(4848);var index_js_=__webpack_require__(8556);var index_mjs_=__webpack_require__(2773);var modern_index_js_=__webpack_require__(7714);var IntegrationsApi=__webpack_require__(6699);const AppConfigCtx=/*#__PURE__*/(0,index_js_.createContext)(null);const AppConfigProvider=AppConfigCtx.Provider;function useAppConfig(){const config=(0,index_js_.useContext)(AppConfigCtx);if(!config)throw new Error("Called `useAppConfig` outside a `<AppConfigProvider />`");return config}function useApi(){const config=useAppConfig();const client=new IntegrationsApi.Qq({baseUrl:config.api.replace(/\/$/,""),baseApiParams:{headers:{Authorization:config.token?`Bearer ${config.token}`:"",From:config.owner}}});return new IntegrationsApi.qx(client)}function useStatsQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","stats",config.company],queryFn:async()=>await api.connectors.getStatsConnectorsV1({cid:config.company}).then(x=>x.data),staleTime:6e4,refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}function useConnectorsListQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","list",config.company],queryFn:async()=>await api.connectors.getConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}var connector_bubble=__webpack_require__(4184);var tabler_icons_react_mjs_=__webpack_require__(5200);var esm_index_mjs_=__webpack_require__(4931);function useConnectorDeleteMutation(){const api=useApi();const config=useAppConfig();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async connector=>{const res=await api.connectors.deleteConnectorV1({cid:config.company,connector});return res.data},onSuccess:()=>{queryClient.invalidateQueries({queryKey:["connectors","list",config.company]});queryClient.invalidateQueries({queryKey:["connectors","list","ill",config.company]});queryClient.invalidateQueries({queryKey:["connectors","catalog",config.company]});queryClient.invalidateQueries({queryKey:["connectors","stats",config.company]});esm_index_mjs_.notifications.show({color:"green",title:"Connecteur supprim\xe9",message:"Vous pouvez le r\xe9ajouter depuis le catalogue."})},onError:error=>{console.error(error);esm_index_mjs_.notifications.show({color:"red",title:"Suppression \xe9chou\xe9e",message:"R\xe9essayez dans un instant."})}})}var modals_esm_index_mjs_=__webpack_require__(4403);function isDeleteConfirmInput(input){return"DELETE"===input}function DeleteActiveBody({name,onConfirm}){const[input,setInput]=(0,index_js_.useState)("");const isMatch=isDeleteConfirmInput(input);const handleConfirm=()=>{if(!isMatch)return;onConfirm();modals_esm_index_mjs_.modals.closeAll()};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",children:["Le connecteur ",/*#__PURE__*/(0,jsx_runtime.jsx)("strong",{children:name})," est actuellement actif. Sa suppression arr\xeatera la synchronisation et le retirera de la liste. Vous pourrez le r\xe9ajouter depuis le catalogue plus tard."]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",children:["Pour confirmer, tapez ",/*#__PURE__*/(0,jsx_runtime.jsx)("strong",{children:"DELETE"})," ci-dessous."]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{value:input,onChange:e=>setInput(e.currentTarget.value),placeholder:"DELETE",autoFocus:true,onKeyDown:e=>{if("Enter"===e.key)handleConfirm()}}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"default",onClick:()=>modals_esm_index_mjs_.modals.closeAll(),children:"Annuler"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{color:"red",disabled:!isMatch,onClick:handleConfirm,children:"Supprimer"})]})]})}function openDeleteActiveConnectorModal(name,onConfirm){modals_esm_index_mjs_.modals.open({title:"Supprimer ce connecteur ?",centered:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(DeleteActiveBody,{name:name,onConfirm:onConfirm})})}function ConnectorMenu({connectorId,connectorName,isActive}){const{mutate,isPending}=useConnectorDeleteMutation();const handleDelete=()=>{if(isActive)openDeleteActiveConnectorModal(connectorName,()=>mutate(connectorId));else mutate(connectorId)};const stopBubble=e=>{e.stopPropagation();e.preventDefault()};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu,{position:"bottom-end",withinPortal:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Target,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{variant:"subtle",color:"gray","aria-label":"Actions du connecteur",onClick:stopBubble,children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconDots,{size:18})})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Dropdown,{onClick:stopBubble,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{color:"red",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTrash,{size:16}),onClick:handleDelete,disabled:isPending,children:"Supprimer"})})]})}function ListOkComponent(){const config=useAppConfig();const listResultRes=useConnectorsListQuery();const listResult=listResultRes.data;return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:2,children:"Tous vos connecteurs en marche"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",style:{alignItems:"stretch"},children:listResult?.list?.map((connector,idx)=>connector?.main_connectorlist?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Card,{pos:"relative",style:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Anchor,{underline:"never",href:`/company/${config.company}/integrations/${connector.id}/connector`,children:/*#__PURE__*/(0,jsx_runtime.jsx)(connector_bubble.q,{connector:connector})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{pos:"absolute",top:8,right:8,children:/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorMenu,{connectorId:connector.id,connectorName:connector.name,isActive:true})})]},idx):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{radius:"md",animate:true},idx))})]})}function useConnectorsIllListQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","list","ill",config.company],queryFn:async()=>await api.connectors.getIllConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}function ListIllComponent(){const config=useAppConfig();const listResultRes=useConnectorsIllListQuery();const listResult=listResultRes.data;return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:2,children:"Tous vos connecteurs \xe0 configurer"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",style:{alignItems:"stretch"},children:listResult?.list?.map((connector,idx)=>connector?.main_connectorlist?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Card,{pos:"relative",style:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Anchor,{underline:"never",href:`/company/${config.company}/integrations/${connector.id}/connector`,children:/*#__PURE__*/(0,jsx_runtime.jsx)(connector_bubble.q,{connector:connector})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{pos:"absolute",top:8,right:8,children:/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorMenu,{connectorId:connector.id,connectorName:connector.name,isActive:false})})]},idx):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{radius:"md",animate:true},idx))})]})}function useConnectorAddMutation(){const api=useApi();const config=useAppConfig();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:async connector_id=>{const res=await api.connectors.addConnectorV1({cid:config.company},{connector_id});return res.data},onSuccess:()=>{queryClient.invalidateQueries({queryKey:["connectors","catalog",config.company]});queryClient.invalidateQueries({queryKey:["connectors","list",config.company]});queryClient.invalidateQueries({queryKey:["connectors","list","ill",config.company]});queryClient.invalidateQueries({queryKey:["connectors","stats",config.company]})}})}function useConnectorCatalogQuery(){const api=useApi();const config=useAppConfig();const query=(0,modern_index_js_.useQuery)({queryKey:["connectors","catalog",config.company],queryFn:async()=>await api.connectors.getCatalogConnectorsV1({cid:config.company}).then(x=>x.data),refetchIntervalInBackground:false,refetchOnWindowFocus:true,refetchOnReconnect:true});return query}function normalize(value){return(value??"").toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,"")}function getBaseName(name){return name.replace(/\s+via\s+.+$/i,"").trim()}function getMethodSuffix(name,baseName){return name.length>baseName.length?name.slice(baseName.length).trim():name}function getLogoUrl(logoKey,codename){return logoKey?`https://img.logo.dev/${logoKey}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${codename}.png`}function GroupCard({group,pending}){const{colorScheme}=(0,index_mjs_.useMantineColorScheme)();const bg="dark"===colorScheme?"white":"dark";const first=group.items[0];const logoUrl=getLogoUrl(group.logoKey,first.codename);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"flex-start",children:[pending?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Loader,{size:64}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:logoUrl,size:64,radius:"md",bg:bg,color:"dark"===colorScheme?"black":"white",p:18}),group.items.length>1&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Badge,{variant:"light",color:"blue",children:[group.items.length," m\xe9thodes"]})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",order:3,children:group.baseName}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"lg",lineClamp:3,children:first.description_fr})]})})}function MethodChoiceCard({item,baseName,pending,disabled,onClick}){const suffix=getMethodSuffix(item.name,baseName);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{style:{cursor:disabled?"wait":"pointer",opacity:disabled&&!pending?.5:1},onClick:()=>{if(!disabled)onClick()},children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",align:"center",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,style:{flex:1},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{fw:600,children:suffix||item.name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{variant:"light",color:"gray",children:item.sharing_method})]}),item.description_fr&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",lineClamp:2,children:item.description_fr})]}),pending&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Loader,{size:"sm"})]})})}function ListCatalogComponent(){const config=useAppConfig();const result=useConnectorCatalogQuery();const list=result.data?.list;const[searchValue,setSearchValue]=(0,index_js_.useState)("");const[pendingId,setPendingId]=(0,index_js_.useState)(null);const[selectedGroup,setSelectedGroup]=(0,index_js_.useState)(null);const mutation=useConnectorAddMutation();const filtered=(0,index_js_.useMemo)(()=>{if(!list)return;const q=normalize(searchValue);if(!q)return list;return list.filter(item=>normalize(`${item.name} ${item.description_fr??""}`).includes(q))},[list,searchValue]);const sections=(0,index_js_.useMemo)(()=>{if(!filtered)return;const groups=new Map;for(const item of filtered){const baseName=getBaseName(item.name);const groupKey=`${item.logo_key??item.codename}::${baseName}`;if(!groups.has(groupKey))groups.set(groupKey,{groupKey,baseName,type:item.type,logoKey:item.logo_key,items:[]});groups.get(groupKey).items.push(item)}const byCategory=new Map;for(const group of groups.values()){const k=group.type.codename;if(!byCategory.has(k))byCategory.set(k,{type:group.type,groups:[]});byCategory.get(k).groups.push(group)}return Array.from(byCategory.values())},[filtered]);const triggerAdd=id=>{setPendingId(id);mutation.mutate(id,{onSuccess:data=>{window.location.href=`/company/${config.company}/integrations/${data.id}/connector`},onError:()=>{setPendingId(null)}})};const handleGroupClick=group=>{if(mutation.isPending)return;if(1===group.items.length)triggerAdd(group.items[0].id);else setSelectedGroup(group)};const handleCloseModal=()=>{if(mutation.isPending)return;setSelectedGroup(null);setPendingId(null)};return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:2,children:"Connecteurs disponibles"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{placeholder:"Rechercher un connecteur...",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconSearch,{size:16}),value:searchValue,onChange:e=>setSearchValue(e.currentTarget.value),size:"md"}),sections?sections.map(section=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:3,children:section.type.name}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",style:{alignItems:"stretch"},children:section.groups.map(group=>{const isSinglePending=1===group.items.length&&pendingId===group.items[0].id;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{style:{height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between",cursor:mutation.isPending?"wait":"pointer",opacity:mutation.isPending&&!isSinglePending?.5:1},onClick:()=>handleGroupClick(group),children:/*#__PURE__*/(0,jsx_runtime.jsx)(GroupCard,{group:group,pending:isSinglePending})},group.groupKey)})})]},section.type.codename)):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SimpleGrid,{cols:{md:4,sm:2,xs:1},spacing:"md",children:Array.from({length:8}).map((_,idx)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{height:180,radius:"md",animate:true},idx))}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:null!==selectedGroup,onClose:handleCloseModal,title:selectedGroup?.baseName??"",size:"lg",children:selectedGroup&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"Choisir une m\xe9thode de connexion :"}),selectedGroup.items.map(item=>/*#__PURE__*/(0,jsx_runtime.jsx)(MethodChoiceCard,{item:item,baseName:selectedGroup.baseName,pending:pendingId===item.id,disabled:mutation.isPending,onClick:()=>triggerAdd(item.id)},item.id))]})})]})}var dist_index_js_=__webpack_require__(6584);function ConnectorsApp(){const tab=(0,dist_index_js_.useRxState)(new URL(location.href).searchParams.get("tab")??"active");const statsResultRes=useStatsQuery();const statsResult=statsResultRes.data;const[tabValue,setTabValue]=(0,index_js_.useState)(tab.value??"active");(0,index_js_.useEffect)(()=>{tab.dispatch(tabValue)},[tabValue]);return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{py:16,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:0,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{w:"fit-content",mb:0,order:1,children:"Nos connecteurs"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{w:"fit-content",mb:0,c:"dimmed",fz:"h5",children:"Synchronisez vos comptes bancaires et outils comptables facilement."})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{py:16,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.SegmentedControl,{value:tabValue,onChange:setTabValue,radius:"md",size:"xl",data:[{label:`Connecteurs actifs(${statsResult?.ok?statsResult.ok:0})`,value:"active"},{label:`Connecteurs \xe0 configurer (${statsResult?.ill?statsResult.ill:0})`,value:"ill"},{label:`Connecteurs en maintenance (${statsResult?.maintenance?statsResult.maintenance:0})`,value:"maintenance"},{label:"Tous les connecteurs",value:"all"}]})}),"active"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)(ListOkComponent,{}),"ill"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)(ListIllComponent,{}),"maintenance"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)("p",{children:"page under progress"}),"all"===tabValue&&/*#__PURE__*/(0,jsx_runtime.jsx)(ListCatalogComponent,{})]})}var dist_esm_index_mjs_=__webpack_require__(4449);const theme=(0,index_mjs_.createTheme)((0,dist_esm_index_mjs_.assign)(dist_index_js_.theme,{components:{}}));const cssVarResolver=x=>(0,dist_esm_index_mjs_.assign)(dist_index_js_.cssVarResolver(x),{dark:{},light:{},variables:{}});function Providers(props){const{children,config,mantine,tanstack}=props;return/*#__PURE__*/(0,jsx_runtime.jsx)(AppConfigProvider,{value:config,children:/*#__PURE__*/(0,jsx_runtime.jsx)(modern_index_js_.QueryClientProvider,{client:tanstack?.queryClient??new modern_index_js_.QueryClient,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.MantineProvider,{theme:theme,cssVariablesResolver:cssVarResolver,defaultColorScheme:mantine?.defaultColorScheme,forceColorScheme:mantine?.forceColorScheme,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(modals_esm_index_mjs_.ModalsProvider,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(esm_index_mjs_.Notifications,{}),children]})})})})}function Connectors(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(Providers,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorsApp,{})})})}},4184:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{q:()=>ConnectorBubble});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(4848);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(2773);function ConnectorBubble({connector}){const{colorScheme}=(0,_mantine_core__WEBPACK_IMPORTED_MODULE_1__.useMantineColorScheme)();const bg="dark"===colorScheme?"white":"dark";const logoUrl=connector.main_connectorlist.logo_key?`https://img.logo.dev/${connector.main_connectorlist.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${connector.main_connectorlist.codename}.png`;return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Card,{children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Stack,{children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Avatar,{src:logoUrl,size:64,radius:"md",bg:bg,color:"dark"===colorScheme?"black":"white",p:18}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Title,{w:"fit-content",order:3,children:connector.name}),/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Text,{c:"dimmed",size:"lg",lineClamp:3,children:connector.main_connectorlist.description_fr})]})})}},6699:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{Qq:()=>HttpClient,qx:()=>IntegrationsApi});class HttpClient{baseUrl="";securityData=null;securityWorker;abortControllers=new Map;customFetch=(...fetchParams)=>fetch(...fetchParams);baseApiParams={credentials:"same-origin",headers:{},redirect:"follow",referrerPolicy:"no-referrer"};constructor(apiConfig={}){Object.assign(this,apiConfig)}setSecurityData=data=>{this.securityData=data};encodeQueryParam(key,value){const encodedKey=encodeURIComponent(key);return`${encodedKey}=${encodeURIComponent("number"==typeof value?value:`${value}`)}`}addQueryParam(query,key){return this.encodeQueryParam(key,query[key])}addArrayQueryParam(query,key){const value=query[key];return value.map(v=>this.encodeQueryParam(key,v)).join("&")}toQueryString(rawQuery){const query=rawQuery||{};const keys=Object.keys(query).filter(key=>void 0!==query[key]);return keys.map(key=>Array.isArray(query[key])?this.addArrayQueryParam(query,key):this.addQueryParam(query,key)).join("&")}addQueryParams(rawQuery){const queryString=this.toQueryString(rawQuery);return queryString?`?${queryString}`:""}contentFormatters={["application/json"]:input=>null!==input&&("object"==typeof input||"string"==typeof input)?JSON.stringify(input):input,["application/vnd.api+json"]:input=>null!==input&&("object"==typeof input||"string"==typeof input)?JSON.stringify(input):input,["text/plain"]:input=>null!==input&&"string"!=typeof input?JSON.stringify(input):input,["multipart/form-data"]:input=>{if(input instanceof FormData)return input;return Object.keys(input||{}).reduce((formData,key)=>{const property=input[key];formData.append(key,property instanceof Blob?property:"object"==typeof property&&null!==property?JSON.stringify(property):`${property}`);return formData},new FormData)},["application/x-www-form-urlencoded"]:input=>this.toQueryString(input)};mergeRequestParams(params1,params2){return{...this.baseApiParams,...params1,...params2||{},headers:{...this.baseApiParams.headers||{},...params1.headers||{},...params2&&params2.headers||{}}}}createAbortSignal=cancelToken=>{if(this.abortControllers.has(cancelToken)){const abortController=this.abortControllers.get(cancelToken);if(abortController)return abortController.signal;return}const abortController=new AbortController;this.abortControllers.set(cancelToken,abortController);return abortController.signal};abortRequest=cancelToken=>{const abortController=this.abortControllers.get(cancelToken);if(abortController){abortController.abort();this.abortControllers.delete(cancelToken)}};request=async({body,secure,path,type,query,format,baseUrl,cancelToken,...params})=>{const secureParams=("boolean"==typeof secure?secure:this.baseApiParams.secure)&&this.securityWorker&&await this.securityWorker(this.securityData)||{};const requestParams=this.mergeRequestParams(params,secureParams);const queryString=query&&this.toQueryString(query);const payloadFormatter=this.contentFormatters[type||"application/json"];const responseFormat=format||requestParams.format;return this.customFetch(`${baseUrl||this.baseUrl||""}${path}${queryString?`?${queryString}`:""}`,{...requestParams,headers:{...requestParams.headers||{},...type&&"multipart/form-data"!==type?{"Content-Type":type}:{}},signal:(cancelToken?this.createAbortSignal(cancelToken):requestParams.signal)||null,body:null==body?null:payloadFormatter(body)}).then(async response=>{const r=response;r.data=null;r.error=null;const responseToParse=responseFormat?response.clone():response;const data=responseFormat?await responseToParse[responseFormat]().then(data=>{if(r.ok)r.data=data;else r.error=data;return r}).catch(e=>{r.error=e;return r}):r;if(cancelToken)this.abortControllers.delete(cancelToken);if(!response.ok)throw data;return data})}}class IntegrationsApi{http;constructor(http){this.http=http}status=(params={})=>this.http.request({path:"/status",method:"GET",...params});connectors={getStatsConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/stats`,method:"GET",secure:true,format:"json",...params}),getConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/ok`,method:"GET",secure:true,format:"json",...params}),getIllConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/ill`,method:"GET",secure:true,format:"json",...params}),getCatalogConnectorsV1:({cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/catalog`,method:"GET",secure:true,format:"json",...params}),addConnectorV1:({cid,...query},data,params={})=>this.http.request({path:`/v1/connectors/${cid}/add`,method:"POST",body:data,secure:true,type:"application/json",format:"json",...params}),getConnectorConfigV1:({connector,cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/config/${connector}`,method:"GET",format:"json",...params}),getConnectorSingleV1:({connector,cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/single/${connector}`,method:"GET",format:"json",...params}),putConnectorDataV1:({connector,cid,...query},data,params={})=>this.http.request({path:`/v1/connectors/${cid}/data/${connector}`,method:"PUT",body:data,type:"application/json",format:"json",...params}),deleteConnectorV1:({connector,cid,...query},params={})=>this.http.request({path:`/v1/connectors/${cid}/${connector}`,method:"DELETE",secure:true,...params})}}}}]);
@@ -7,4 +7,4 @@
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */var REACT_ELEMENT_TYPE=Symbol.for("react.transitional.element"),REACT_FRAGMENT_TYPE=Symbol.for("react.fragment");function jsxProd(type,config,maybeKey){var key=null;void 0!==maybeKey&&(key=""+maybeKey);void 0!==config.key&&(key=""+config.key);if("key"in config){maybeKey={};for(var propName in config)"key"!==propName&&(maybeKey[propName]=config[propName])}else maybeKey=config;config=maybeKey.ref;return{$$typeof:REACT_ELEMENT_TYPE,type:type,key:key,ref:void 0!==config?config:null,props:maybeKey}}exports.Fragment=REACT_FRAGMENT_TYPE;exports.jsx=jsxProd;exports.jsxs=jsxProd},4848:function(module,__unused_webpack_exports,__webpack_require__){module.exports=__webpack_require__(9698)},115:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>Synchronisation});var jsx_runtime=__webpack_require__(4848);var index_js_=__webpack_require__(8556);var index_mjs_=__webpack_require__(2773);var InlineLoader=__webpack_require__(800);var modern_index_js_=__webpack_require__(7714);const AppConfigSynchroCtx=/*#__PURE__*/(0,index_js_.createContext)(null);const AppConfigSynchroProvider=AppConfigSynchroCtx.Provider;function useAppConfigSynchro(){const config=(0,index_js_.useContext)(AppConfigSynchroCtx);if(!config)throw new Error("Called `useAppConfigSynchro` outside a `<AppConfigSynchroProvider />`");return config}function useApiSynchro(){const config=useAppConfigSynchro();const baseUrl=config.api.replace(/\/$/,"");const headers={"Content-Type":"application/json",Authorization:config.token?`Bearer ${config.token}`:"",From:config.owner};const handleResponse=async res=>{if(!res.ok)throw new Error(`${res.status} ${res.statusText}`);return res.json()};return{get:path=>fetch(`${baseUrl}${path}`,{headers}).then(handleResponse),post:(path,body)=>fetch(`${baseUrl}${path}`,{method:"POST",headers,body:void 0!==body?JSON.stringify(body):void 0}).then(handleResponse),put:(path,body)=>fetch(`${baseUrl}${path}`,{method:"PUT",headers,body:void 0!==body?JSON.stringify(body):void 0}).then(handleResponse),delete:path=>fetch(`${baseUrl}${path}`,{method:"DELETE",headers}).then(handleResponse)}}function useSynchroListQuery(){const api=useApiSynchro();const config=useAppConfigSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","list",config.company],queryFn:()=>api.get(`/synchro?cid=${config.company}`),refetchOnWindowFocus:true,refetchOnReconnect:true})}function useSynchroDetailQuery(id){const api=useApiSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","detail",id],queryFn:()=>api.get(`/synchro/${id}`),enabled:null!==id,refetchOnWindowFocus:true,refetchOnReconnect:true,refetchInterval:query=>{const tasks=query.state.data?.tasks??[];const hasRunning=tasks.some(t=>null!==t.startedAt&&!t.finished);return hasRunning?5e3:false}})}var esm_index_mjs_=__webpack_require__(4931);function useSynchroRunMutation(){const api=useApiSynchro();const config=useAppConfigSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:id=>api.post(`/synchro/${id}/run`),onSuccess:(_,id)=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});queryClient.invalidateQueries({queryKey:["synchro","list",config.company]});esm_index_mjs_.notifications.show({title:"Recette lanc\xe9e",message:"La synchronisation a d\xe9marr\xe9."})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de lancer la recette."})}})}function useSynchroToggleMutation(){const api=useApiSynchro();const config=useAppConfigSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,active})=>api.put(`/synchro/${id}`,{active}),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});queryClient.invalidateQueries({queryKey:["synchro","list",config.company]})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de modifier la recette."})}})}var tabler_icons_react_mjs_=__webpack_require__(5200);function statusColor(customer){if(!customer.active)return"gray";const task=customer.lastTask;if(!task)return"gray";if(!task.finished)return"yellow";return task.error?"red":"green"}function connectorLogoUrl(c){return c.logo_key?`https://img.logo.dev/${c.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${c.codename}.png`}function ConnectorLogo({connector}){if(!connector)return null;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:connector.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:connectorLogoUrl(connector),size:44,radius:"md",p:0,style:{flexShrink:0}})})}function isOverviewRecipe(r){return"Total"===r.recipe.name||"[Total]"===r.recipe.name}function SynchroList({recipes,selectedId,onSelect}){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ScrollArea,{h:"100%",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Stack,{gap:8,p:8,children:recipes.map(r=>{const color=statusColor(r);const isSelected=r.id===selectedId;const from=r.recipe.connector_from;const to=r.recipe.connector_to;const isOverview=isOverviewRecipe(r);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.UnstyledButton,{onClick:()=>onSelect(r.id),style:{borderLeft:`3px solid var(--mantine-color-${color}-6)`,background:isSelected?"var(--mantine-color-dark-6)":"transparent",borderRadius:4,padding:"6px 10px"},children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:8,wrap:"nowrap",justify:"center",children:isOverview?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"Vue d'ensemble",withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:6,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconHome,{size:20}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:"Vue d'ensemble"})]})}):from||to?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:12,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorLogo,{connector:from}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"lg",c:"dimmed",children:"→"}),/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorLogo,{connector:to})]}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",truncate:true,children:r.recipe.name})})},r.id)})})})}function useSynchroJobRunMutation(){const api=useApiSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,jobId})=>api.post(`/synchro/${id}/jobs/${jobId}/run`),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});esm_index_mjs_.notifications.show({title:"T\xe2che lanc\xe9e",message:"La t\xe2che a d\xe9marr\xe9."})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de lancer la t\xe2che."})}})}function jobStatusColor(job){const task=job.lastTask;if(!task)return"gray";if(!task.finished)return"yellow";return task.error?"red":"green"}function synchro_functions_connectorLogoUrl(c){return c.logo_key?`https://img.logo.dev/${c.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${c.codename}.png`}function JobLogos({job}){if(!job.connector_from&&!job.connector_to)return null;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:3,wrap:"nowrap",style:{flexShrink:0},children:[job.connector_from&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:job.connector_from.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_functions_connectorLogoUrl(job.connector_from),size:20,radius:"md",p:0})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:"→"}),job.connector_to&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:job.connector_to.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_functions_connectorLogoUrl(job.connector_to),size:20,radius:"md",p:0})})]})}function SynchroFunctions({detail,onConfigJob}){const runJob=useSynchroJobRunMutation();return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Grid,{gutter:"md",children:detail.jobs.map(job=>{const color=jobStatusColor(job);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Grid.Col,{span:{base:12,sm:6},children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{p:"md",withBorder:true,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:8,wrap:"nowrap",style:{flex:1,minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{w:8,h:8,style:{borderRadius:"50%",background:`var(--mantine-color-${color}-6)`,flexShrink:0}}),/*#__PURE__*/(0,jsx_runtime.jsx)(JobLogos,{job:job}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",truncate:true,children:job.task_fr})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:4,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"green",loading:runJob.isPending,title:"Lancer",onClick:()=>runJob.mutate({id:detail.id,jobId:job.id}),children:"▶"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"gray",title:"Configurer",onClick:()=>onConfigJob(job),children:"⚙"})]})]})})},job.id)})})}function formatDuration(ms){if(null===ms)return"—";if(ms<1e3)return`${ms}ms`;const secs=ms/1e3;if(secs<60)return`${secs.toFixed(1)}s`;const mins=Math.floor(secs/60);const remainSecs=Math.round(secs%60);return`${mins}mn ${remainSecs}s`}function formatDate(iso){if(!iso)return"—";return new Date(iso).toLocaleString("fr-FR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}function synchro_history_connectorLogoUrl(c){return c.logo_key?`https://img.logo.dev/${c.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${c.codename}.png`}function TaskLogos({task}){if(!task.connector_from&&!task.connector_to)return null;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:3,wrap:"nowrap",children:[task.connector_from&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:task.connector_from.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_history_connectorLogoUrl(task.connector_from),size:20,radius:"md",p:0})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:"→"}),task.connector_to&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:task.connector_to.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_history_connectorLogoUrl(task.connector_to),size:20,radius:"md",p:0})})]})}function SynchroHistory({tasks}){const showRecipeCol=tasks.some(t=>t.connector_from||t.connector_to);if(0===tasks.length)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",children:"Aucun historique disponible."});return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table,{striped:true,highlightOnHover:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Thead,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[showRecipeCol&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Recette"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"T\xe2che"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"D\xe9marr\xe9e"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Statut"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Dur\xe9e"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"#ops"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Logs"})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tbody,{children:tasks.map(task=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[showRecipeCol&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(TaskLogos,{task:task})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.job_name_fr}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:formatDate(task.startedAt)}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.finished?task.error?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:"red",children:"Erreur"}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:"green",children:"OK"}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:"yellow",children:"En cours"})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:formatDuration(task.runDuration)}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.trace_count}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.grafana_url?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Anchor,{href:task.grafana_url,target:"_blank",size:"sm",children:"Logs"}):"—"})]},task.id))})]})}function useSynchroJobConfigQuery(recipeId,jobId){const api=useApiSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","job-config",recipeId,jobId],queryFn:()=>api.get(`/synchro/${recipeId}/jobs/${jobId}/config`),enabled:null!==recipeId&&null!==jobId})}function useSynchroJobSaveMutation(){const api=useApiSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,jobId,data})=>api.put(`/synchro/${id}/jobs/${jobId}`,data),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});esm_index_mjs_.notifications.show({title:"Configuration sauvegard\xe9e",message:"Les param\xe8tres sont enregistr\xe9s."})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de sauvegarder la configuration."})}})}var form_esm_index_mjs_=__webpack_require__(4491);var dates_esm_index_mjs_=__webpack_require__(5899);const START_PRESETS=[{value:"today",label:"Jour courant"},{value:"month_start",label:"D\xe9but du mois"},{value:"prev_month_start",label:"D\xe9but du mois pr\xe9c\xe9dent"},{value:"year_start",label:"D\xe9but de l'ann\xe9e"}];const END_PRESETS=[{value:"today",label:"Jour courant"},{value:"month_end",label:"Fin du mois"},{value:"prev_month_end",label:"Fin du mois pr\xe9c\xe9dent"},{value:"year_end",label:"Fin de l'ann\xe9e"}];const MODE_VALUES={TODAY:"today",MONTH_START:"month_start",PREV_MONTH_START:"prev_month_start",YEAR_START:"year_start",MONTH_END:"month_end",PREV_MONTH_END:"prev_month_end",YEAR_END:"year_end"};const MODE_KEYS={today:"TODAY",month_start:"MONTH_START",prev_month_start:"PREV_MONTH_START",year_start:"YEAR_START",month_end:"MONTH_END",prev_month_end:"PREV_MONTH_END",year_end:"YEAR_END",exact:"",relative:""};function parseValue(val){const defaults={exactDate:null,direction:"MINUS",amount:1,unit:"DAYS"};if(!val)return{mode:"today",...defaults};if(MODE_VALUES[val])return{mode:MODE_VALUES[val],...defaults};const relMatch=val.match(/^(MINUS|PLUS):(\d+):(\w+)$/);if(relMatch)return{mode:"relative",exactDate:null,direction:relMatch[1],amount:Number(relMatch[2]),unit:relMatch[3]};const d=new Date(val);if(!isNaN(d.getTime()))return{mode:"exact",exactDate:d,...defaults};return{mode:"today",...defaults}}function serializeValue(mode,exactDate,direction,amount,unit){if("exact"===mode)return exactDate?exactDate.toISOString():"";if("relative"===mode)return`${direction}:${amount}:${unit}`;return MODE_KEYS[mode]||"TODAY"}function InputDateBoundary({label,help,required,disabled,value,onChange,variant}){const parsed=parseValue(value);const[mode,setMode]=(0,index_js_.useState)(parsed.mode);const[exactDate,setExactDate]=(0,index_js_.useState)(parsed.exactDate);const[direction,setDirection]=(0,index_js_.useState)(parsed.direction);const[amount,setAmount]=(0,index_js_.useState)(parsed.amount);const[unit,setUnit]=(0,index_js_.useState)(parsed.unit);(0,index_js_.useEffect)(()=>{onChange(serializeValue(mode,exactDate,direction,amount,unit))},[mode,exactDate,direction,amount,unit]);const presets="start"===variant?START_PRESETS:END_PRESETS;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"xs",children:[label&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",fw:500,children:[label," ",required&&/*#__PURE__*/(0,jsx_runtime.jsx)("span",{style:{color:"var(--mantine-color-red-6)"},children:"*"})]}),help&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:help}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio.Group,{value:mode,onChange:v=>setMode(v),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"md",wrap:"nowrap",grow:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio,{value:"exact",label:"Date exacte",disabled:disabled}),/*#__PURE__*/(0,jsx_runtime.jsx)(dates_esm_index_mjs_.DateInput,{leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconCalendar,{size:16}),value:exactDate,onChange:d=>{setExactDate(d);setMode("exact")},disabled:disabled||"exact"!==mode,valueFormat:"DD-MM-YYYY",placeholder:"JJ-MM-AAAA"})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"md",wrap:"nowrap",grow:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio,{value:"relative",label:"Date relative",disabled:disabled}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{data:[{value:"MINUS",label:"pass\xe9e"},{value:"PLUS",label:"future"}],value:direction,onChange:v=>{setDirection(v??"MINUS");setMode("relative")},disabled:disabled||"relative"!==mode,w:100}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{value:amount,onChange:v=>{setAmount(Number(v));setMode("relative")},min:0,disabled:disabled||"relative"!==mode,w:70}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{data:[{value:"DAYS",label:"Jour(s)"},{value:"MONTHS",label:"Mois"},{value:"YEARS",label:"Ann\xe9e(s)"}],value:unit,onChange:v=>{setUnit(v??"DAYS");setMode("relative")},disabled:disabled||"relative"!==mode,w:110})]}),presets.map(p=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio,{value:p.value,label:p.label,disabled:disabled},p.value))]})})]})}function useSpreadsheetsQuery(){const api=useApiSynchro();const config=useAppConfigSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","spreadsheets",config.company],queryFn:()=>api.get(`/synchro/spreadsheets?cid=${config.company}`)})}function InputGsheetsSelector({label,help,required,disabled,value,onChange,error}){const{data:spreadsheets,isPending}=useSpreadsheetsQuery();const options=(spreadsheets??[]).map(s=>({value:s.id,label:s.name}));return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{label:label??"Tableur",description:help??void 0,required:required,disabled:disabled||isPending,placeholder:isPending?"Chargement...":"S\xe9lectionner un tableur",data:options,value:value,onChange:onChange,error:error,searchable:true,clearable:true})}function FormField({config,value,onChange,error}){const label=config.label??config.name??"";const description=config.help??void 0;const required=config.required??false;const disabled=config.disabled??false;const selectOptions=(()=>{if(!config.full||"object"!=typeof config.full)return[];const f=config.full;if(Array.isArray(f.options))return f.options.map(o=>"string"==typeof o?{value:o,label:o}:{value:String(o.value??o.id??o),label:o.label??o.name??String(o)});return[]})();switch(config.type){case"text":if(config.multiple)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TagsInput,{label:label,description:description,required:required,disabled:disabled,value:Array.isArray(value)?value:value?[value]:[],onChange:onChange,error:error});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:e=>onChange(e.currentTarget.value),error:error});case"email":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{type:"email",label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:e=>onChange(e.currentTarget.value),error:error});case"password":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.PasswordInput,{label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:e=>onChange(e.currentTarget.value),error:error});case"hidden":return null;case"msg":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",c:"dimmed",children:label});case"switch":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{label:label,description:description,disabled:disabled,checked:!!value,onChange:e=>onChange(e.currentTarget.checked)});case"select":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{label:label,description:description,required:required,disabled:disabled,data:selectOptions,value:value??null,onChange:onChange,error:error,searchable:true});case"date_boundary_start":return/*#__PURE__*/(0,jsx_runtime.jsx)(InputDateBoundary,{label:label,help:description,required:required,disabled:disabled,value:value,onChange:onChange,variant:"start"});case"date_boundary_end":return/*#__PURE__*/(0,jsx_runtime.jsx)(InputDateBoundary,{label:label,help:description,required:required,disabled:disabled,value:value,onChange:onChange,variant:"end"});case"tags_multiple":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TagsInput,{label:label,description:description,required:required,disabled:disabled,value:Array.isArray(value)?value:value?String(value).split(",").filter(Boolean):[],onChange:onChange,error:error});case"gsheets_account_selector":return/*#__PURE__*/(0,jsx_runtime.jsx)(InputGsheetsSelector,{label:label,help:description,required:required,disabled:disabled,value:value,onChange:onChange,error:error});case"number":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:onChange,error:error});case"checkbox":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Checkbox,{label:label,description:description,disabled:disabled,checked:!!value,onChange:e=>onChange(e.currentTarget.checked)});case"multi_select":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.MultiSelect,{label:label,description:description,required:required,disabled:disabled,data:selectOptions,value:Array.isArray(value)?value:[],onChange:onChange,error:error,searchable:true});case"recipe_cf_pipedrive":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TagsInput,{label:label,description:description,required:required,disabled:disabled,value:Array.isArray(value)?value:value?String(value).split(",").filter(Boolean):[],onChange:onChange,error:error});default:return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Alert,{variant:"light",color:"yellow",title:`Type "${config.type}" non support\xe9`,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"xs",children:["Champ : ",config.name]})})}}function SynchroDynamicForm({config,save}){const form=(0,form_esm_index_mjs_.useForm)({initialValues:config.data?.initialData??{}});(0,index_js_.useEffect)(()=>{if(config.data?.initialData){form.setValues(config.data.initialData);form.resetDirty()}},[config.data]);if(config.isPending||!config.data)return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{height:30,mt:6,radius:"xl"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{height:12,mt:6,w:"30%",radius:"xl"})]});const{sections}=config.data;if(!sections?.length)return null;return/*#__PURE__*/(0,jsx_runtime.jsx)("form",{autoComplete:"off",onSubmit:form.onSubmit(values=>save.mutate(values)),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[sections.map((section,si)=>section.fields.map((fieldConfig,fi)=>/*#__PURE__*/(0,jsx_runtime.jsx)(FormField,{config:fieldConfig,value:form.values[fieldConfig.name],onChange:value=>form.setFieldValue(fieldConfig.name,value),error:form.errors[fieldConfig.name]},`${si}-${fi}`))),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{justify:"flex-end",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{type:"submit",loading:save.isPending,children:"Enregistrer"})})]})})}function JobConfigModal({job,recipeId,opened,onClose}){const save=useSynchroJobSaveMutation();const configQuery=useSynchroJobConfigQuery(opened?recipeId:null,opened?job?.id??null:null);const saveMutation=(0,index_js_.useMemo)(()=>({...save,mutate:values=>{if(!job)return;save.mutate({id:recipeId,jobId:job.id,data:values})}}),[save,job,recipeId]);if(!job)return null;const hasForm=configQuery.data?.sections?.length>0;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Modal,{opened:opened,onClose:onClose,title:job.task_fr,size:"lg",children:[configQuery.isPending||hasForm?/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroDynamicForm,{config:configQuery,save:saveMutation}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",children:"Aucune configuration disponible pour cette t\xe2che."}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{justify:"flex-end",mt:"md",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"subtle",color:"gray",onClick:onClose,children:"Fermer"})})]})}var hooks_esm_index_mjs_=__webpack_require__(2667);function useCreateScheduleMutation(){const api=useApiSynchro();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({recipeCustomerId,data})=>api.post(`/synchro/${recipeCustomerId}/schedules`,data),onSuccess:()=>qc.invalidateQueries({queryKey:["synchro"]})})}function useUpdateScheduleMutation(){const api=useApiSynchro();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({recipeCustomerId,scheduleId,data})=>api.put(`/synchro/${recipeCustomerId}/schedules/${scheduleId}`,data),onSuccess:()=>qc.invalidateQueries({queryKey:["synchro"]})})}function useDeleteScheduleMutation(){const api=useApiSynchro();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({recipeCustomerId,scheduleId})=>api.delete(`/synchro/${recipeCustomerId}/schedules/${scheduleId}`),onSuccess:()=>qc.invalidateQueries({queryKey:["synchro"]})})}const DAY_LABELS={monday:"Lun",tuesday:"Mar",wednesday:"Mer",thursday:"Jeu",friday:"Ven",saturday:"Sam",sunday:"Dim"};const ALL_DAYS=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"];function SynchroSchedules({schedules,jobs,recipeCustomerId}){const[opened,{open,close}]=(0,hooks_esm_index_mjs_.useDisclosure)(false);const[editing,setEditing]=(0,index_js_.useState)(null);const handleEdit=s=>{setEditing(s);open()};const handleNew=()=>{setEditing(null);open()};return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[0===schedules.length&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",children:"Aucun d\xe9clencheur configur\xe9."}),schedules.map(s=>/*#__PURE__*/(0,jsx_runtime.jsx)(ScheduleCard,{schedule:s,jobs:jobs,recipeCustomerId:recipeCustomerId,onEdit:()=>handleEdit(s)},s.id)),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"light",size:"xs",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconPlus,{size:14}),onClick:handleNew,w:"fit-content",children:"Ajouter un d\xe9clencheur"})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ScheduleModal,{opened:opened,onClose:close,schedule:editing,jobs:jobs,recipeCustomerId:recipeCustomerId})]})}function ScheduleCard({schedule,jobs,recipeCustomerId,onEdit}){const deleteMut=useDeleteScheduleMutation();const hour=String(schedule.hour??0).padStart(2,"0");const minute=String(schedule.minute??0).padStart(2,"0");const taskLabels=schedule.tasks.map(t=>{const job=jobs.find(j=>String(j.id)===t);return job?.active?job.task_fr:null}).filter(Boolean);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{withBorder:true,p:"sm",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:6,style:{flex:1},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconClock,{size:16}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",fw:500,children:[hour,":",minute]}),schedule.frequency&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{variant:"light",size:"sm",children:schedule.frequency}),schedule.draft&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{variant:"light",size:"sm",color:"yellow",children:"Brouillon"})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconCalendar,{size:16}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:4,children:ALL_DAYS.map(day=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",variant:schedule.days.includes(day)?"filled":"light",color:schedule.days.includes(day)?"teal":"gray",children:DAY_LABELS[day]},day))})]}),taskLabels.length>0&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:4,wrap:"wrap",children:taskLabels.map((label,i)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",variant:"outline",children:label},i))})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",onClick:onEdit,title:"Modifier",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconPencil,{size:14})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"red",loading:deleteMut.isPending,onClick:()=>deleteMut.mutate({recipeCustomerId,scheduleId:schedule.id}),title:"Supprimer",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTrash,{size:14})})]})]})})}function ScheduleModal({opened,onClose,schedule,jobs,recipeCustomerId}){const createMut=useCreateScheduleMutation();const updateMut=useUpdateScheduleMutation();const[days,setDays]=(0,index_js_.useState)(ALL_DAYS);const[hour,setHour]=(0,index_js_.useState)(1);const[minute,setMinute]=(0,index_js_.useState)(0);const[selectedTasks,setSelectedTasks]=(0,index_js_.useState)([]);(0,index_js_.useEffect)(()=>{if(schedule){setDays(schedule.days);setHour(schedule.hour??1);setMinute(schedule.minute??0);setSelectedTasks(schedule.tasks)}else{setDays(ALL_DAYS);setHour(1);setMinute(0);setSelectedTasks([])}},[schedule,opened]);const toggleDay=day=>{setDays(prev=>prev.includes(day)?prev.filter(d=>d!==day):[...prev,day])};const toggleTask=task=>{setSelectedTasks(prev=>prev.includes(task)?prev.filter(t=>t!==task):[...prev,task])};const handleSave=()=>{const data={days,hour,minute,tasks:selectedTasks};if(schedule)updateMut.mutate({recipeCustomerId,scheduleId:schedule.id,data},{onSuccess:onClose});else createMut.mutate({recipeCustomerId,data},{onSuccess:onClose})};const isPending=createMut.isPending||updateMut.isPending;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:opened,onClose:onClose,title:schedule?"Modifier le d\xe9clencheur":"Nouveau d\xe9clencheur",size:"md",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{label:"Heure",value:hour,onChange:v=>setHour(Number(v)),min:0,max:23,w:80}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{label:"Minute",value:minute,onChange:v=>setMinute(Number(v)),min:0,max:59,w:80})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",fw:500,children:"Jours"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:4,children:ALL_DAYS.map(day=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"lg",variant:days.includes(day)?"filled":"light",color:days.includes(day)?"teal":"gray",style:{cursor:"pointer"},onClick:()=>toggleDay(day),children:DAY_LABELS[day]},day))})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",fw:500,children:"Jobs \xe0 d\xe9clencher"}),jobs.map(job=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Checkbox,{label:job.task_fr??job.task,checked:selectedTasks.includes(String(job.id)),onChange:()=>toggleTask(String(job.id))},job.id))]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"subtle",color:"gray",onClick:onClose,children:"Annuler"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{onClick:handleSave,loading:isPending,children:schedule?"Enregistrer":"Cr\xe9er"})]})]})})}function SynchroApp(){const[selectedId,setSelectedIdState]=(0,index_js_.useState)(()=>{const param=new URLSearchParams(window.location.search).get("recipeId");const parsed=param?Number(param):NaN;return Number.isInteger(parsed)&&parsed>0?parsed:null});const[configJob,setConfigJob]=(0,index_js_.useState)(null);const listRes=useSynchroListQuery();const detailRes=useSynchroDetailQuery(selectedId);const runAll=useSynchroRunMutation();const toggle=useSynchroToggleMutation();const recipes=listRes.data??[];const detail=detailRes.data;const setSelectedId=(0,index_js_.useCallback)(id=>{setSelectedIdState(id);const url=new URL(window.location.href);if(null===id)url.searchParams.delete("recipeId");else url.searchParams.set("recipeId",String(id));window.history.replaceState({},"",url)},[]);(0,index_js_.useEffect)(()=>{if(0===recipes.length)return;const exists=null!==selectedId&&recipes.some(r=>r.id===selectedId);if(!exists)setSelectedId(recipes[0].id)},[recipes,selectedId,setSelectedId]);if(listRes.isPending)return/*#__PURE__*/(0,jsx_runtime.jsx)(InlineLoader.F,{label:"Chargement des synchronisations..."});return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{wrap:"nowrap",h:"100%",align:"flex-start",gap:0,children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Box,{w:220,h:"100%",style:{flexShrink:0,borderRight:"1px solid var(--mantine-color-dark-5)"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:5,p:"sm",c:"dimmed",children:"Synchronisations"}),0===recipes.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",c:"dimmed",px:"sm",children:"Aucune recette configur\xe9e."}):/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroList,{recipes:recipes,selectedId:selectedId,onSelect:setSelectedId})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{flex:1,p:"md",style:{overflowY:"auto"},children:null===selectedId?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"S\xe9lectionnez une recette."}):detailRes.isPending?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{h:40}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{h:120}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{h:200})]}):detail?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"lg",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:3,children:"Total"===detail.recipe.name||"[Total]"===detail.recipe.name?"Vue d'ensemble":detail.recipe.name}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{checked:detail.active,label:detail.active?"Actif":"Inactif",onChange:()=>toggle.mutate({id:detail.id,active:!detail.active})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"light",color:"green",loading:runAll.isPending,onClick:()=>runAll.mutate(detail.id),children:"▶ Lancer tout"})]})]}),!("Total"===detail.recipe.name||"[Total]"===detail.recipe.name)&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:5,c:"dimmed",children:"D\xe9clencheurs"}),/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroSchedules,{schedules:detail.schedules,jobs:detail.jobs,recipeCustomerId:detail.id})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroFunctions,{detail:detail,onConfigJob:setConfigJob}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:5,c:"dimmed",children:"Historique"}),/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroHistory,{tasks:detail.tasks})]})]}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"Impossible de charger la recette."})})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(JobConfigModal,{job:configJob,recipeId:selectedId??0,opened:null!==configJob,onClose:()=>setConfigJob(null)})]})}var dist_index_js_=__webpack_require__(6584);var modals_esm_index_mjs_=__webpack_require__(4403);var dist_esm_index_mjs_=__webpack_require__(4449);const theme=(0,index_mjs_.createTheme)((0,dist_esm_index_mjs_.assign)(dist_index_js_.theme,{components:{}}));const cssVarResolver=x=>(0,dist_esm_index_mjs_.assign)(dist_index_js_.cssVarResolver(x),{dark:{},light:{},variables:{}});function ProvidersSynchro(props){const{children,config,mantine,tanstack}=props;return/*#__PURE__*/(0,jsx_runtime.jsx)(AppConfigSynchroProvider,{value:config,children:/*#__PURE__*/(0,jsx_runtime.jsx)(modern_index_js_.QueryClientProvider,{client:tanstack?.queryClient??new modern_index_js_.QueryClient,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.MantineProvider,{theme:theme,cssVariablesResolver:cssVarResolver,defaultColorScheme:mantine?.defaultColorScheme,forceColorScheme:mantine?.forceColorScheme,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(modals_esm_index_mjs_.ModalsProvider,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(esm_index_mjs_.Notifications,{}),children]})})})})}function Synchronisation(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(ProvidersSynchro,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroApp,{})})})}},800:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{F:()=>InlineLoader});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(4848);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(2773);function InlineLoader({label}){return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Center,{flex:1,h:"100%",children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Stack,{align:"center",gap:"md",children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Loader,{size:"md",color:"teal"}),label&&/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Text,{fz:"sm",c:"dimmed",children:label})]})})}}}]);
10
+ */var REACT_ELEMENT_TYPE=Symbol.for("react.transitional.element"),REACT_FRAGMENT_TYPE=Symbol.for("react.fragment");function jsxProd(type,config,maybeKey){var key=null;void 0!==maybeKey&&(key=""+maybeKey);void 0!==config.key&&(key=""+config.key);if("key"in config){maybeKey={};for(var propName in config)"key"!==propName&&(maybeKey[propName]=config[propName])}else maybeKey=config;config=maybeKey.ref;return{$$typeof:REACT_ELEMENT_TYPE,type:type,key:key,ref:void 0!==config?config:null,props:maybeKey}}exports.Fragment=REACT_FRAGMENT_TYPE;exports.jsx=jsxProd;exports.jsxs=jsxProd},4848:function(module,__unused_webpack_exports,__webpack_require__){module.exports=__webpack_require__(9698)},7461:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{default:()=>Synchronisation});var jsx_runtime=__webpack_require__(4848);var index_js_=__webpack_require__(8556);var index_mjs_=__webpack_require__(2773);var InlineLoader=__webpack_require__(800);var modern_index_js_=__webpack_require__(7714);const AppConfigSynchroCtx=/*#__PURE__*/(0,index_js_.createContext)(null);const AppConfigSynchroProvider=AppConfigSynchroCtx.Provider;function useAppConfigSynchro(){const config=(0,index_js_.useContext)(AppConfigSynchroCtx);if(!config)throw new Error("Called `useAppConfigSynchro` outside a `<AppConfigSynchroProvider />`");return config}function useApiSynchro(){const config=useAppConfigSynchro();const baseUrl=config.api.replace(/\/$/,"");const headers={"Content-Type":"application/json",Authorization:config.token?`Bearer ${config.token}`:"",From:config.owner};const handleResponse=async res=>{if(!res.ok)throw new Error(`${res.status} ${res.statusText}`);return res.json()};return{get:path=>fetch(`${baseUrl}${path}`,{headers}).then(handleResponse),post:(path,body)=>fetch(`${baseUrl}${path}`,{method:"POST",headers,body:void 0!==body?JSON.stringify(body):void 0}).then(handleResponse),put:(path,body)=>fetch(`${baseUrl}${path}`,{method:"PUT",headers,body:void 0!==body?JSON.stringify(body):void 0}).then(handleResponse),delete:path=>fetch(`${baseUrl}${path}`,{method:"DELETE",headers}).then(handleResponse)}}function useSynchroListQuery(){const api=useApiSynchro();const config=useAppConfigSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","list",config.company],queryFn:()=>api.get(`/synchro?cid=${config.company}`),refetchOnWindowFocus:true,refetchOnReconnect:true})}function useSynchroDetailQuery(id){const api=useApiSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","detail",id],queryFn:()=>api.get(`/synchro/${id}`),enabled:null!==id,refetchOnWindowFocus:true,refetchOnReconnect:true,refetchInterval:query=>{const tasks=query.state.data?.tasks??[];const hasRunning=tasks.some(t=>null!==t.startedAt&&!t.finished);return hasRunning?5e3:false}})}var esm_index_mjs_=__webpack_require__(4931);function useSynchroRunMutation(){const api=useApiSynchro();const config=useAppConfigSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:id=>api.post(`/synchro/${id}/run`),onSuccess:(_,id)=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});queryClient.invalidateQueries({queryKey:["synchro","list",config.company]});esm_index_mjs_.notifications.show({title:"Recette lanc\xe9e",message:"La synchronisation a d\xe9marr\xe9."})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de lancer la recette."})}})}function useSynchroToggleMutation(){const api=useApiSynchro();const config=useAppConfigSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,active})=>api.put(`/synchro/${id}`,{active}),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});queryClient.invalidateQueries({queryKey:["synchro","list",config.company]})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de modifier la recette."})}})}var tabler_icons_react_mjs_=__webpack_require__(5200);function statusColor(customer){if(!customer.active)return"gray";const task=customer.lastTask;if(!task)return"gray";if(!task.finished)return"yellow";return task.error?"red":"green"}function connectorLogoUrl(c){return c.logo_key?`https://img.logo.dev/${c.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${c.codename}.png`}function ConnectorLogo({connector}){if(!connector)return null;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:connector.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:connectorLogoUrl(connector),size:44,radius:"md",p:0,style:{flexShrink:0}})})}function isOverviewRecipe(r){return"Total"===r.recipe.name||"[Total]"===r.recipe.name}function buildSections(recipes){let overview=null;const byType=new Map;for(const r of recipes){if(isOverviewRecipe(r)){overview=r;continue}const t=r.recipe.connector_from?.type;const key=t?.codename??"other";if(!byType.has(key))byType.set(key,{type:t??{codename:"other",name:"Autres"},recipes:[]});byType.get(key).recipes.push(r)}const sections=Array.from(byType.values()).sort((a,b)=>a.type.name.localeCompare(b.type.name));return{overview,sections}}function RecipeRow({customer,selectedId,onSelect}){const color=statusColor(customer);const isSelected=customer.id===selectedId;const from=customer.recipe.connector_from;const to=customer.recipe.connector_to;const isOverview=isOverviewRecipe(customer);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.UnstyledButton,{onClick:()=>onSelect(customer.id),style:{borderLeft:`3px solid var(--mantine-color-${color}-6)`,background:isSelected?"var(--mantine-color-dark-6)":"transparent",borderRadius:4,padding:"6px 10px"},children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:8,wrap:"nowrap",justify:"center",children:isOverview?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:"Vue d'ensemble",withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:6,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconHome,{size:20}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:"Vue d'ensemble"})]})}):from||to?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:12,wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorLogo,{connector:from}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"lg",c:"dimmed",children:"→"}),/*#__PURE__*/(0,jsx_runtime.jsx)(ConnectorLogo,{connector:to})]}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",truncate:true,children:customer.recipe.name})})})}function SynchroList({recipes,selectedId,onSelect}){const{overview,sections}=buildSections(recipes);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ScrollArea,{h:"100%",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:8,p:8,children:[overview&&/*#__PURE__*/(0,jsx_runtime.jsx)(RecipeRow,{customer:overview,selectedId:selectedId,onSelect:onSelect}),sections.map(section=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:6,c:"dimmed",pl:10,pt:6,children:section.type.name}),section.recipes.map(r=>/*#__PURE__*/(0,jsx_runtime.jsx)(RecipeRow,{customer:r,selectedId:selectedId,onSelect:onSelect},r.id))]},section.type.codename))]})})}var modals_esm_index_mjs_=__webpack_require__(4403);function useSynchroJobRunMutation(){const api=useApiSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,jobId})=>api.post(`/synchro/${id}/jobs/${jobId}/run`),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});esm_index_mjs_.notifications.show({title:"T\xe2che lanc\xe9e",message:"La t\xe2che a d\xe9marr\xe9."})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de lancer la t\xe2che."})}})}function useSynchroJobToggleMutation(){const api=useApiSynchro();const config=useAppConfigSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,jobId,active})=>api.put(`/synchro/${id}/jobs/${jobId}/active`,{active}),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});queryClient.invalidateQueries({queryKey:["synchro","list",config.company]})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de modifier la t\xe2che."})}})}function useSynchroJobDeleteMutation(){const api=useApiSynchro();const config=useAppConfigSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,jobId})=>api.delete(`/synchro/${id}/jobs/${jobId}`),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});queryClient.invalidateQueries({queryKey:["synchro","list",config.company]})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de supprimer la t\xe2che."})}})}function jobStatusColor(job){const task=job.lastTask;if(!task)return"gray";if(!task.finished)return"yellow";return task.error?"red":"green"}function synchro_functions_connectorLogoUrl(c){return c.logo_key?`https://img.logo.dev/${c.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${c.codename}.png`}function JobLogos({job}){if(!job.connector_from&&!job.connector_to)return null;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:3,wrap:"nowrap",style:{flexShrink:0},children:[job.connector_from&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:job.connector_from.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_functions_connectorLogoUrl(job.connector_from),size:20,radius:"md",p:0})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:"→"}),job.connector_to&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:job.connector_to.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_functions_connectorLogoUrl(job.connector_to),size:20,radius:"md",p:0})})]})}function SynchroFunctions({detail,onConfigJob}){const runJob=useSynchroJobRunMutation();const toggleJob=useSynchroJobToggleMutation();const deleteJob=useSynchroJobDeleteMutation();return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Grid,{gutter:"md",children:detail.jobs.map(job=>{const color=jobStatusColor(job);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Grid.Col,{span:{base:12,sm:6},children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{p:"md",withBorder:true,style:{cursor:"pointer"},onClick:()=>onConfigJob(job),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:8,wrap:"nowrap",style:{flex:1,minWidth:0},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{w:8,h:8,style:{borderRadius:"50%",background:`var(--mantine-color-${color}-6)`,flexShrink:0}}),/*#__PURE__*/(0,jsx_runtime.jsx)(JobLogos,{job:job}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{truncate:true,style:{fontSize:"1.09375rem"},children:job.task_fr})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:4,wrap:"nowrap",onClick:e=>e.stopPropagation(),children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"green",loading:runJob.isPending,title:"Lancer",onClick:()=>runJob.mutate({id:detail.id,jobId:job.id}),children:"▶"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"gray",title:"Configurer",onClick:()=>onConfigJob(job),children:"⚙"}),(job.allow_disable||job.allow_delete)&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu,{shadow:"md",width:180,position:"bottom-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Target,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"gray",title:"Plus d'options",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconDotsVertical,{size:16})})}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Menu.Dropdown,{children:[job.allow_disable&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconCpuOff,{size:14}),onClick:()=>{if(job.active)modals_esm_index_mjs_.modals.openConfirmModal({title:"D\xe9sactiver cette t\xe2che ?",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:"La t\xe2che ne sera plus ex\xe9cut\xe9e tant qu'elle reste d\xe9sactiv\xe9e."}),labels:{confirm:"D\xe9sactiver",cancel:"Annuler"},onConfirm:()=>toggleJob.mutate({id:detail.id,jobId:job.id,active:false})});else toggleJob.mutate({id:detail.id,jobId:job.id,active:true})},children:job.active?"D\xe9sactiver":"Activer"}),job.allow_delete&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Menu.Item,{color:"red",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTrash,{size:14}),onClick:()=>{modals_esm_index_mjs_.modals.openConfirmModal({title:"Supprimer cette t\xe2che ?",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",children:"Cette action est irr\xe9versible. La configuration de la t\xe2che sera perdue."}),labels:{confirm:"Supprimer",cancel:"Annuler"},confirmProps:{color:"red"},onConfirm:()=>deleteJob.mutate({id:detail.id,jobId:job.id})})},children:"Supprimer"})]})]})]})]})})},job.id)})})}function formatDuration(ms){if(null===ms)return"—";if(ms<1e3)return`${ms}ms`;const secs=ms/1e3;if(secs<60)return`${secs.toFixed(1)}s`;const mins=Math.floor(secs/60);const remainSecs=Math.round(secs%60);return`${mins}mn ${remainSecs}s`}function formatDate(iso){if(!iso)return"—";return new Date(iso).toLocaleString("fr-FR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}function synchro_history_connectorLogoUrl(c){return c.logo_key?`https://img.logo.dev/${c.logo_key}?token=pk_QvyqAb6uTRGJE2_sDsEb9g&retina=true`:`https://s3.eu-west-3.amazonaws.com/media.airporting/connectors/${c.codename}.png`}function TaskLogos({task}){if(!task.connector_from&&!task.connector_to)return null;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:3,wrap:"nowrap",children:[task.connector_from&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:task.connector_from.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_history_connectorLogoUrl(task.connector_from),size:20,radius:"md",p:0})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:"→"}),task.connector_to&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Tooltip,{label:task.connector_to.name,withArrow:true,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Avatar,{src:synchro_history_connectorLogoUrl(task.connector_to),size:20,radius:"md",p:0})})]})}function SynchroHistory({tasks}){const showRecipeCol=tasks.some(t=>t.connector_from||t.connector_to);if(0===tasks.length)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",children:"Aucun historique disponible."});return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table,{striped:true,highlightOnHover:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Thead,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[showRecipeCol&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Recette"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"T\xe2che"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"D\xe9marr\xe9e"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Statut"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Dur\xe9e"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"#ops"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Th,{children:"Logs"})]})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Tbody,{children:tasks.map(task=>/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Table.Tr,{children:[showRecipeCol&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(TaskLogos,{task:task})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.job_name_fr}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:formatDate(task.startedAt)}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.finished?task.error?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:"red",children:"Erreur"}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:"green",children:"OK"}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{color:"yellow",children:"En cours"})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:formatDuration(task.runDuration)}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.trace_count}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Table.Td,{children:task.grafana_url?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Anchor,{href:task.grafana_url,target:"_blank",size:"sm",children:"Logs"}):"—"})]},task.id))})]})}function useSynchroJobConfigQuery(recipeId,jobId){const api=useApiSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","job-config",recipeId,jobId],queryFn:()=>api.get(`/synchro/${recipeId}/jobs/${jobId}/config`),enabled:null!==recipeId&&null!==jobId})}function useSynchroJobSaveMutation(){const api=useApiSynchro();const queryClient=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({id,jobId,data})=>api.put(`/synchro/${id}/jobs/${jobId}`,data),onSuccess:(_,{id})=>{queryClient.invalidateQueries({queryKey:["synchro","detail",id]});esm_index_mjs_.notifications.show({title:"Configuration sauvegard\xe9e",message:"Les param\xe8tres sont enregistr\xe9s."})},onError:()=>{esm_index_mjs_.notifications.show({color:"red",title:"Erreur",message:"Impossible de sauvegarder la configuration."})}})}var form_esm_index_mjs_=__webpack_require__(4491);var dates_esm_index_mjs_=__webpack_require__(5899);const START_PRESETS=[{value:"today",label:"Jour courant"},{value:"month_start",label:"D\xe9but du mois"},{value:"prev_month_start",label:"D\xe9but du mois pr\xe9c\xe9dent"},{value:"year_start",label:"D\xe9but de l'ann\xe9e"}];const END_PRESETS=[{value:"today",label:"Jour courant"},{value:"month_end",label:"Fin du mois"},{value:"prev_month_end",label:"Fin du mois pr\xe9c\xe9dent"},{value:"year_end",label:"Fin de l'ann\xe9e"}];const MODE_VALUES={TODAY:"today",MONTH_START:"month_start",PREV_MONTH_START:"prev_month_start",YEAR_START:"year_start",MONTH_END:"month_end",PREV_MONTH_END:"prev_month_end",YEAR_END:"year_end"};const MODE_KEYS={today:"TODAY",month_start:"MONTH_START",prev_month_start:"PREV_MONTH_START",year_start:"YEAR_START",month_end:"MONTH_END",prev_month_end:"PREV_MONTH_END",year_end:"YEAR_END",exact:"",relative:""};function parseValue(val){const defaults={exactDate:null,direction:"MINUS",amount:1,unit:"DAYS"};if(!val)return{mode:"today",...defaults};if(MODE_VALUES[val])return{mode:MODE_VALUES[val],...defaults};const relMatch=val.match(/^(MINUS|PLUS):(\d+):(\w+)$/);if(relMatch)return{mode:"relative",exactDate:null,direction:relMatch[1],amount:Number(relMatch[2]),unit:relMatch[3]};const d=new Date(val);if(!isNaN(d.getTime()))return{mode:"exact",exactDate:d,...defaults};return{mode:"today",...defaults}}function serializeValue(mode,exactDate,direction,amount,unit){if("exact"===mode)return exactDate?exactDate.toISOString():"";if("relative"===mode)return`${direction}:${amount}:${unit}`;return MODE_KEYS[mode]||"TODAY"}function InputDateBoundary({label,help,required,disabled,value,onChange,variant}){const parsed=parseValue(value);const[mode,setMode]=(0,index_js_.useState)(parsed.mode);const[exactDate,setExactDate]=(0,index_js_.useState)(parsed.exactDate);const[direction,setDirection]=(0,index_js_.useState)(parsed.direction);const[amount,setAmount]=(0,index_js_.useState)(parsed.amount);const[unit,setUnit]=(0,index_js_.useState)(parsed.unit);(0,index_js_.useEffect)(()=>{onChange(serializeValue(mode,exactDate,direction,amount,unit))},[mode,exactDate,direction,amount,unit]);const presets="start"===variant?START_PRESETS:END_PRESETS;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"xs",children:[label&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",fw:500,children:[label," ",required&&/*#__PURE__*/(0,jsx_runtime.jsx)("span",{style:{color:"var(--mantine-color-red-6)"},children:"*"})]}),help&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"xs",c:"dimmed",children:help}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio.Group,{value:mode,onChange:v=>setMode(v),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"md",wrap:"nowrap",grow:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio,{value:"exact",label:"Date exacte",disabled:disabled}),/*#__PURE__*/(0,jsx_runtime.jsx)(dates_esm_index_mjs_.DateInput,{leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconCalendar,{size:16}),value:exactDate,onChange:d=>{setExactDate(d);setMode("exact")},disabled:disabled||"exact"!==mode,valueFormat:"DD-MM-YYYY",placeholder:"JJ-MM-AAAA"})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"md",wrap:"nowrap",grow:true,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio,{value:"relative",label:"Date relative",disabled:disabled}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{data:[{value:"MINUS",label:"pass\xe9e"},{value:"PLUS",label:"future"}],value:direction,onChange:v=>{setDirection(v??"MINUS");setMode("relative")},disabled:disabled||"relative"!==mode,w:100}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{value:amount,onChange:v=>{setAmount(Number(v));setMode("relative")},min:0,disabled:disabled||"relative"!==mode,w:70}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{data:[{value:"DAYS",label:"Jour(s)"},{value:"MONTHS",label:"Mois"},{value:"YEARS",label:"Ann\xe9e(s)"}],value:unit,onChange:v=>{setUnit(v??"DAYS");setMode("relative")},disabled:disabled||"relative"!==mode,w:110})]}),presets.map(p=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Radio,{value:p.value,label:p.label,disabled:disabled},p.value))]})})]})}function useSpreadsheetsQuery(){const api=useApiSynchro();const config=useAppConfigSynchro();return(0,modern_index_js_.useQuery)({queryKey:["synchro","spreadsheets",config.company],queryFn:()=>api.get(`/synchro/spreadsheets?cid=${config.company}`)})}function InputGsheetsSelector({label,help,required,disabled,value,onChange,error}){const{data:spreadsheets,isPending}=useSpreadsheetsQuery();const options=(spreadsheets??[]).map(s=>({value:s.id,label:s.name}));return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{label:label??"Tableur",description:help??void 0,required:required,disabled:disabled||isPending,placeholder:isPending?"Chargement...":"S\xe9lectionner un tableur",data:options,value:value,onChange:onChange,error:error,searchable:true,clearable:true})}function FormField({config,value,onChange,error}){const label=config.label??config.name??"";const description=config.help??void 0;const required=config.required??false;const disabled=config.disabled??false;const selectOptions=(()=>{if(!config.full||"object"!=typeof config.full)return[];const f=config.full;if(Array.isArray(f.options))return f.options.map(o=>"string"==typeof o?{value:o,label:o}:{value:String(o.value??o.id??o),label:o.label??o.name??String(o)});return[]})();switch(config.type){case"text":if(config.multiple)return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TagsInput,{label:label,description:description,required:required,disabled:disabled,value:Array.isArray(value)?value:value?[value]:[],onChange:onChange,error:error});return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:e=>onChange(e.currentTarget.value),error:error});case"email":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TextInput,{type:"email",label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:e=>onChange(e.currentTarget.value),error:error});case"password":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.PasswordInput,{label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:e=>onChange(e.currentTarget.value),error:error});case"hidden":return null;case"msg":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",c:"dimmed",children:label});case"switch":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{label:label,description:description,disabled:disabled,checked:!!value,onChange:e=>onChange(e.currentTarget.checked)});case"select":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Select,{label:label,description:description,required:required,disabled:disabled,data:selectOptions,value:value??null,onChange:onChange,error:error,searchable:true});case"date_boundary_start":return/*#__PURE__*/(0,jsx_runtime.jsx)(InputDateBoundary,{label:label,help:description,required:required,disabled:disabled,value:value,onChange:onChange,variant:"start"});case"date_boundary_end":return/*#__PURE__*/(0,jsx_runtime.jsx)(InputDateBoundary,{label:label,help:description,required:required,disabled:disabled,value:value,onChange:onChange,variant:"end"});case"tags_multiple":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TagsInput,{label:label,description:description,required:required,disabled:disabled,value:Array.isArray(value)?value:value?String(value).split(",").filter(Boolean):[],onChange:onChange,error:error});case"gsheets_account_selector":return/*#__PURE__*/(0,jsx_runtime.jsx)(InputGsheetsSelector,{label:label,help:description,required:required,disabled:disabled,value:value,onChange:onChange,error:error});case"number":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{label:label,description:description,required:required,disabled:disabled,value:value??"",onChange:onChange,error:error});case"checkbox":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Checkbox,{label:label,description:description,disabled:disabled,checked:!!value,onChange:e=>onChange(e.currentTarget.checked)});case"multi_select":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.MultiSelect,{label:label,description:description,required:required,disabled:disabled,data:selectOptions,value:Array.isArray(value)?value:[],onChange:onChange,error:error,searchable:true});case"recipe_cf_pipedrive":return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.TagsInput,{label:label,description:description,required:required,disabled:disabled,value:Array.isArray(value)?value:value?String(value).split(",").filter(Boolean):[],onChange:onChange,error:error});default:return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Alert,{variant:"light",color:"yellow",title:`Type "${config.type}" non support\xe9`,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"xs",children:["Champ : ",config.name]})})}}function SynchroDynamicForm({config,save}){const form=(0,form_esm_index_mjs_.useForm)({initialValues:config.data?.initialData??{}});(0,index_js_.useEffect)(()=>{if(config.data?.initialData){form.setValues(config.data.initialData);form.resetDirty()}},[config.data]);if(config.isPending||!config.data)return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{height:30,mt:6,radius:"xl"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{height:12,mt:6,w:"30%",radius:"xl"})]});const{sections}=config.data;if(!sections?.length)return null;return/*#__PURE__*/(0,jsx_runtime.jsx)("form",{autoComplete:"off",onSubmit:form.onSubmit(values=>save.mutate(values)),children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[sections.map((section,si)=>section.fields.map((fieldConfig,fi)=>/*#__PURE__*/(0,jsx_runtime.jsx)(FormField,{config:fieldConfig,value:form.values[fieldConfig.name],onChange:value=>form.setFieldValue(fieldConfig.name,value),error:form.errors[fieldConfig.name]},`${si}-${fi}`))),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{justify:"flex-end",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{type:"submit",loading:save.isPending,children:"Enregistrer"})})]})})}function JobConfigModal({job,recipeId,opened,onClose}){const save=useSynchroJobSaveMutation();const configQuery=useSynchroJobConfigQuery(opened?recipeId:null,opened?job?.id??null:null);const saveMutation=(0,index_js_.useMemo)(()=>({...save,mutate:values=>{if(!job)return;save.mutate({id:recipeId,jobId:job.id,data:values})}}),[save,job,recipeId]);if(!job)return null;const hasForm=configQuery.data?.sections?.length>0;return/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Modal,{opened:opened,onClose:onClose,title:job.task_fr,size:"lg",children:[configQuery.isPending||hasForm?/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroDynamicForm,{config:configQuery,save:saveMutation}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",children:"Aucune configuration disponible pour cette t\xe2che."}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{justify:"flex-end",mt:"md",children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"subtle",color:"gray",onClick:onClose,children:"Fermer"})})]})}var hooks_esm_index_mjs_=__webpack_require__(2667);function useCreateScheduleMutation(){const api=useApiSynchro();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({recipeCustomerId,data})=>api.post(`/synchro/${recipeCustomerId}/schedules`,data),onSuccess:()=>qc.invalidateQueries({queryKey:["synchro"]})})}function useUpdateScheduleMutation(){const api=useApiSynchro();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({recipeCustomerId,scheduleId,data})=>api.put(`/synchro/${recipeCustomerId}/schedules/${scheduleId}`,data),onSuccess:()=>qc.invalidateQueries({queryKey:["synchro"]})})}function useDeleteScheduleMutation(){const api=useApiSynchro();const qc=(0,modern_index_js_.useQueryClient)();return(0,modern_index_js_.useMutation)({mutationFn:({recipeCustomerId,scheduleId})=>api.delete(`/synchro/${recipeCustomerId}/schedules/${scheduleId}`),onSuccess:()=>qc.invalidateQueries({queryKey:["synchro"]})})}const DAY_LABELS={monday:"Lun",tuesday:"Mar",wednesday:"Mer",thursday:"Jeu",friday:"Ven",saturday:"Sam",sunday:"Dim"};const ALL_DAYS=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"];function SynchroSchedules({schedules,jobs,recipeCustomerId}){const[opened,{open,close}]=(0,hooks_esm_index_mjs_.useDisclosure)(false);const[editing,setEditing]=(0,index_js_.useState)(null);const handleEdit=s=>{setEditing(s);open()};const handleNew=()=>{setEditing(null);open()};return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"sm",children:[0===schedules.length&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",size:"sm",children:"Aucun d\xe9clencheur configur\xe9."}),schedules.map(s=>/*#__PURE__*/(0,jsx_runtime.jsx)(ScheduleCard,{schedule:s,jobs:jobs,recipeCustomerId:recipeCustomerId,onEdit:()=>handleEdit(s)},s.id)),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"light",size:"xs",leftSection:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconPlus,{size:14}),onClick:handleNew,w:"fit-content",children:"Ajouter un d\xe9clencheur"})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(ScheduleModal,{opened:opened,onClose:close,schedule:editing,jobs:jobs,recipeCustomerId:recipeCustomerId})]})}function ScheduleCard({schedule,jobs,recipeCustomerId,onEdit}){const deleteMut=useDeleteScheduleMutation();const hour=String(schedule.hour??0).padStart(2,"0");const minute=String(schedule.minute??0).padStart(2,"0");const taskLabels=schedule.tasks.map(t=>{const job=jobs.find(j=>String(j.id)===t);return job?.active?job.task_fr:null}).filter(Boolean);return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Card,{withBorder:true,p:"sm",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:6,style:{flex:1},children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconClock,{size:16}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Text,{size:"sm",fw:500,children:[hour,":",minute]}),schedule.frequency&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{variant:"light",size:"sm",children:schedule.frequency}),schedule.draft&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{variant:"light",size:"sm",color:"yellow",children:"Brouillon"})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconCalendar,{size:16}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:4,children:ALL_DAYS.map(day=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",variant:schedule.days.includes(day)?"filled":"light",color:schedule.days.includes(day)?"teal":"gray",children:DAY_LABELS[day]},day))})]}),taskLabels.length>0&&/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:4,wrap:"wrap",children:taskLabels.map((label,i)=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"xs",variant:"outline",children:label},i))})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",onClick:onEdit,title:"Modifier",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconPencil,{size:14})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.ActionIcon,{size:"sm",variant:"subtle",color:"red",loading:deleteMut.isPending,onClick:()=>deleteMut.mutate({recipeCustomerId,scheduleId:schedule.id}),title:"Supprimer",children:/*#__PURE__*/(0,jsx_runtime.jsx)(tabler_icons_react_mjs_.IconTrash,{size:14})})]})]})})}function ScheduleModal({opened,onClose,schedule,jobs,recipeCustomerId}){const createMut=useCreateScheduleMutation();const updateMut=useUpdateScheduleMutation();const[days,setDays]=(0,index_js_.useState)(ALL_DAYS);const[hour,setHour]=(0,index_js_.useState)(1);const[minute,setMinute]=(0,index_js_.useState)(0);const[selectedTasks,setSelectedTasks]=(0,index_js_.useState)([]);(0,index_js_.useEffect)(()=>{if(schedule){setDays(schedule.days);setHour(schedule.hour??1);setMinute(schedule.minute??0);setSelectedTasks(schedule.tasks)}else{setDays(ALL_DAYS);setHour(1);setMinute(0);setSelectedTasks([])}},[schedule,opened]);const toggleDay=day=>{setDays(prev=>prev.includes(day)?prev.filter(d=>d!==day):[...prev,day])};const toggleTask=task=>{setSelectedTasks(prev=>prev.includes(task)?prev.filter(t=>t!==task):[...prev,task])};const handleSave=()=>{const data={days,hour,minute,tasks:selectedTasks};if(schedule)updateMut.mutate({recipeCustomerId,scheduleId:schedule.id,data},{onSuccess:onClose});else createMut.mutate({recipeCustomerId,data},{onSuccess:onClose})};const isPending=createMut.isPending||updateMut.isPending;return/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Modal,{opened:opened,onClose:onClose,title:schedule?"Modifier le d\xe9clencheur":"Nouveau d\xe9clencheur",size:"md",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"md",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{label:"Heure",value:hour,onChange:v=>setHour(Number(v)),min:0,max:23,w:80}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.NumberInput,{label:"Minute",value:minute,onChange:v=>setMinute(Number(v)),min:0,max:59,w:80})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",fw:500,children:"Jours"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Group,{gap:4,children:ALL_DAYS.map(day=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Badge,{size:"lg",variant:days.includes(day)?"filled":"light",color:days.includes(day)?"teal":"gray",style:{cursor:"pointer"},onClick:()=>toggleDay(day),children:DAY_LABELS[day]},day))})]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:4,children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",fw:500,children:"Jobs \xe0 d\xe9clencher"}),jobs.map(job=>/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Checkbox,{label:job.task_fr??job.task,checked:selectedTasks.includes(String(job.id)),onChange:()=>toggleTask(String(job.id))},job.id))]}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"flex-end",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"subtle",color:"gray",onClick:onClose,children:"Annuler"}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{onClick:handleSave,loading:isPending,children:schedule?"Enregistrer":"Cr\xe9er"})]})]})})}function SynchroApp(){const[selectedId,setSelectedIdState]=(0,index_js_.useState)(()=>{const param=new URLSearchParams(window.location.search).get("recipeId");const parsed=param?Number(param):NaN;return Number.isInteger(parsed)&&parsed>0?parsed:null});const[configJob,setConfigJob]=(0,index_js_.useState)(null);const listRes=useSynchroListQuery();const detailRes=useSynchroDetailQuery(selectedId);const runAll=useSynchroRunMutation();const toggle=useSynchroToggleMutation();const recipes=listRes.data??[];const detail=detailRes.data;const setSelectedId=(0,index_js_.useCallback)(id=>{setSelectedIdState(id);const url=new URL(window.location.href);if(null===id)url.searchParams.delete("recipeId");else url.searchParams.set("recipeId",String(id));window.history.replaceState({},"",url)},[]);(0,index_js_.useEffect)(()=>{if(0===recipes.length)return;const exists=null!==selectedId&&recipes.some(r=>r.id===selectedId);if(!exists)setSelectedId(recipes[0].id)},[recipes,selectedId,setSelectedId]);if(listRes.isPending)return/*#__PURE__*/(0,jsx_runtime.jsx)(InlineLoader.F,{label:"Chargement des synchronisations..."});return/*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment,{children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{wrap:"nowrap",h:"100%",align:"flex-start",gap:0,children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Box,{w:220,h:"100%",style:{flexShrink:0,borderRight:"1px solid var(--mantine-color-dark-5)"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:5,p:"sm",c:"dimmed",children:"Synchronisations"}),0===recipes.length?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{size:"sm",c:"dimmed",px:"sm",children:"Aucune recette configur\xe9e."}):/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroList,{recipes:recipes,selectedId:selectedId,onSelect:setSelectedId})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Box,{flex:1,p:"md",style:{overflowY:"auto"},children:null===selectedId?/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"S\xe9lectionnez une recette."}):detailRes.isPending?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{h:40}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{h:120}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Skeleton,{h:200})]}):detail?/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"lg",children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{justify:"space-between",wrap:"nowrap",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:3,children:"Total"===detail.recipe.name||"[Total]"===detail.recipe.name?"Vue d'ensemble":detail.recipe.name}),/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Group,{gap:"sm",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Switch,{checked:detail.active,label:detail.active?"Actif":"Inactif",onChange:()=>toggle.mutate({id:detail.id,active:!detail.active})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Button,{variant:"light",color:"green",loading:runAll.isPending,onClick:()=>runAll.mutate(detail.id),children:"▶ Lancer tout"})]})]}),!("Total"===detail.recipe.name||"[Total]"===detail.recipe.name)&&/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Stack,{gap:"xs",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:5,c:"dimmed",children:"D\xe9clencheurs"}),/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroSchedules,{schedules:detail.schedules,jobs:detail.jobs,recipeCustomerId:detail.id})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroFunctions,{detail:detail,onConfigJob:setConfigJob}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Accordion,{defaultValue:null,variant:"default",children:/*#__PURE__*/(0,jsx_runtime.jsxs)(index_mjs_.Accordion.Item,{value:"history",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Accordion.Control,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Title,{order:5,c:"dimmed",children:"Historique"})}),/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Accordion.Panel,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroHistory,{tasks:detail.tasks})})]})})]}):/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.Text,{c:"dimmed",children:"Impossible de charger la recette."})})]}),/*#__PURE__*/(0,jsx_runtime.jsx)(JobConfigModal,{job:configJob,recipeId:selectedId??0,opened:null!==configJob,onClose:()=>setConfigJob(null)})]})}var dist_index_js_=__webpack_require__(6584);var dist_esm_index_mjs_=__webpack_require__(4449);const theme=(0,index_mjs_.createTheme)((0,dist_esm_index_mjs_.assign)(dist_index_js_.theme,{components:{}}));const cssVarResolver=x=>(0,dist_esm_index_mjs_.assign)(dist_index_js_.cssVarResolver(x),{dark:{},light:{},variables:{}});function ProvidersSynchro(props){const{children,config,mantine,tanstack}=props;return/*#__PURE__*/(0,jsx_runtime.jsx)(AppConfigSynchroProvider,{value:config,children:/*#__PURE__*/(0,jsx_runtime.jsx)(modern_index_js_.QueryClientProvider,{client:tanstack?.queryClient??new modern_index_js_.QueryClient,children:/*#__PURE__*/(0,jsx_runtime.jsx)(index_mjs_.MantineProvider,{theme:theme,cssVariablesResolver:cssVarResolver,defaultColorScheme:mantine?.defaultColorScheme,forceColorScheme:mantine?.forceColorScheme,children:/*#__PURE__*/(0,jsx_runtime.jsxs)(modals_esm_index_mjs_.ModalsProvider,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(esm_index_mjs_.Notifications,{}),children]})})})})}function Synchronisation(props){return/*#__PURE__*/(0,jsx_runtime.jsx)(index_js_.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(ProvidersSynchro,{...props,children:/*#__PURE__*/(0,jsx_runtime.jsx)(SynchroApp,{})})})}},800:function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{F:()=>InlineLoader});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(4848);var _mantine_core__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(2773);function InlineLoader({label}){return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Center,{flex:1,h:"100%",children:/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Stack,{align:"center",gap:"md",children:[/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Loader,{size:"md",color:"teal"}),label&&/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_mantine_core__WEBPACK_IMPORTED_MODULE_1__.Text,{fz:"sm",c:"dimmed",children:label})]})})}}}]);