{"version":3,"file":"usePinUnpinMutation-BJ_KDkeq.js","sources":["../../../frontend/src/Hooks/usePinUnpinMutation.ts"],"sourcesContent":["import { useIntl } from 'react-intl';\n\nimport queriesConfig from '../Services/queriesConfig';\nimport Analytics from '../Services/AnalyticsService';\nimport { extractErrorForToaster } from '../Services/ApiErrorHelpers';\nimport { Post } from '../Utils/Types/Posts';\nimport { notify } from '../Utils/NotificationUtils';\nimport useApiMutation from './useApiMutation';\nimport { useNotifications } from '@toolpad/core/useNotifications';\n\nexport default function usePinUnpinMutation({\n post,\n onSuccess,\n}: {\n post: Post;\n onSuccess?: () => void;\n}) {\n const notifications = useNotifications();\n const intl = useIntl();\n\n const { is_pinned: isPinned, id: postId } = post;\n\n return useApiMutation({\n query: queriesConfig.pinUnpin(postId),\n onSuccess: () => {\n const trackingText = isPinned ? 'Post - Pin' : 'Post - Unpin';\n\n Analytics.track(trackingText, {\n 'Post ID': postId,\n });\n\n notify(\n notifications,\n intl.formatMessage({ id: isPinned ? 'POSTS.FORM.UNPIN' : 'POSTS.FORM.PIN' }),\n );\n\n if (onSuccess) onSuccess();\n },\n onError: (error) => {\n notify(notifications, extractErrorForToaster(error, intl));\n notify(notifications, error, 'error');\n },\n });\n}\n"],"names":["usePinUnpinMutation","_ref","post","onSuccess","notifications","useNotifications","intl","useIntl","isPinned","is_pinned","postId","id","useApiMutation","query","queriesConfig","pinUnpin","trackingText","Analytics","track","formatMessage","_onSuccess","onError","error","notify","extractErrorForToaster"],"mappings":"2FAUA,SAAwBA,EAAmBC,EAMxC,CAAA,IALDC,EAAID,EAAJC,KACAC,EAASF,EAATE,UAKMC,EAAgBC,EAAiB,EACjCC,EAAOC,EAAQ,EAEFC,EAAyBN,EAApCO,UAAyBC,EAAWR,EAAfS,GAE7B,OAAOC,EAAe,CACpBC,MAAOC,EAAcC,SAASL,CAAM,EACpCP,UAAW,UAAM,CACTa,IAAAA,EAAeR,EAAW,aAAe,eAE/CS,EAAUC,MAAMF,EAAc,CAC5B,UAAWN,CAAAA,CACZ,EAGCN,EAAAA,EACAE,EAAKa,cAAc,CAAER,GAAIH,EAAW,mBAAqB,gBAAA,CAAkB,CAC7E,EAEIL,GAAqBiB,EAAA,CAC3B,EACAC,QAAS,SAACC,EAAU,CAClBC,EAAOnB,EAAeoB,EAAuBF,EAAOhB,CAAI,CAAC,EAClDF,EAAAA,EAAekB,EAAO,OAAO,CAAA,CACtC,CACD,CACH"}