{"version":3,"file":"useParamsId-BohA3HWs.js","sources":["../../../frontend/src/Hooks/usePostQuery.ts","../../../frontend/src/Hooks/useParamsId.ts"],"sourcesContent":["import { get } from 'lodash';\nimport { useNotifications } from '@toolpad/core/useNotifications';\nimport { useNavigate } from 'react-router-dom';\n\nimport queriesConfig from '../Services/queriesConfig';\nimport { loginPath, spacePath } from '../Utils/routes';\nimport useApiQuery from './useApiQuery';\nimport { notify } from '../Utils/NotificationUtils';\nimport useCurrentUser from './useCurrentUser';\n\nconst usePostQuery = (postId: number | string, useQueryProps?: any) => {\n const navigate = useNavigate();\n const notifications = useNotifications();\n const { isLoggedIn } = useCurrentUser();\n\n const { data, ...params } = useApiQuery({\n query: queriesConfig.getPost(postId),\n options: {\n enabled: !!window.spaceSlug && Boolean(postId),\n keepPreviousData: true,\n refetchOnWindowFocus: false,\n ...useQueryProps,\n },\n onSettled: (response) => {\n if (response && !response.ok) {\n if ([404, 500].includes(response?.status)) {\n navigate(`/${response.status}`);\n }\n\n if (response?.status === 403) {\n notify(notifications, get(response, 'data.errors[0].detail'), 'error');\n\n if (isLoggedIn) {\n navigate(spacePath());\n } else {\n navigate(loginPath());\n }\n }\n }\n },\n });\n\n return {\n post: data,\n ...params,\n };\n};\n\nexport default usePostQuery;\n","import { get } from 'lodash';\nimport { useParams } from 'react-router-dom';\n\nexport default (paramName: string = 'postSlug') => {\n const params = useParams();\n const idFromParams = get(params, paramName)?.match(/\\d+/g)?.[0];\n\n return Number(idFromParams);\n};\n"],"names":["usePostQuery","postId","useQueryProps","navigate","useNavigate","notifications","useNotifications","_useCurrentUser","useCurrentUser","isLoggedIn","_useApiQuery","useApiQuery","query","queriesConfig","getPost","options","_objectSpread","enabled","window","spaceSlug","Boolean","keepPreviousData","refetchOnWindowFocus","onSettled","response","ok","includes","status","concat","notify","get","spacePath","loginPath","data","params","_objectWithoutProperties","_excluded","post","useParamsId","_get","paramName","arguments","length","undefined","useParams","idFromParams","match","Number"],"mappings":"ytDAUA,IAAMA,EAAe,SAACC,EAAyBC,EAAwB,CACrE,IAAMC,EAAWC,EAAY,EACvBC,EAAgBC,EAAiB,EACvCC,EAAuBC,EAAAA,EAAfC,EAAUF,EAAVE,WAERC,EAA4BC,EAAY,CACtCC,MAAOC,EAAcC,QAAQb,CAAM,EACnCc,QAAOC,EAAA,CACLC,QAAS,CAAC,CAACC,OAAOC,WAAaC,EAAQnB,EACvCoB,iBAAkB,GAClBC,qBAAsB,IACnBpB,CAAa,EAElBqB,UAAW,SAACC,EAAa,CACnBA,GAAY,CAACA,EAASC,KACpB,CAAC,IAAK,GAAG,EAAEC,SAASF,GAAQ,KAARA,OAAAA,EAAUG,MAAM,GACtCxB,MAAQyB,OAAKJ,EAASG,MAAM,CAAE,GAG5BH,GAAQ,KAAA,OAARA,EAAUG,UAAW,MACvBE,EAAOxB,EAAeyB,EAAAA,IAAIN,EAAU,uBAAuB,EAAG,OAAO,EAGnErB,EADEM,EACOsB,IAEAC,GAFW,GAK1B,CACF,CACD,EAzBOC,EAAIvB,EAAJuB,KAASC,EAAMC,EAAAzB,EAAA0B,CAAA,EA2BvB,OAAApB,EAAA,CACEqB,KAAMJ,GACHC,CAAM,CAEb,EC3CA,MAAAI,EAAe,UAAoC,CAAAC,IAAAA,EAAnCC,EAAiBC,UAAAC,OAAAD,GAAAA,UAAAE,CAAAA,IAAAA,OAAAF,aAAG,WAC5BP,EAASU,EAAU,EACnBC,GAAYN,EAAGT,MAAII,EAAQM,CAAS,KAAC,MAAAD,IAAA,SAAAA,EAAtBA,EAAwBO,MAAM,MAAM,KAACP,MAAAA,IAArCA,OAAAA,OAAAA,EAAwC,CAAC,EAE9D,OAAOQ,OAAOF,CAAY,CAC5B"}