{"version":3,"file":"UdpQuestionFormBuilderPage.mjs","names":["React","useCallback","useHistory","UdpQuestionFormBuilder","useUser","useTenant","useSnackbar","useUdpFormParameters","UdpQuestionFormBuilderPage","t0","$","_c","formsBaseUrlPath","t1","onFormCreated","undefined","user","tenant","history","enqueueSnackbar","closeSnackbar","formId","formVersion","t2","e","newFormId","detail","version","replace","handleFormCreated","t3","t4","t5"],"sources":["../../../../src/udp/pages/UdpQuestionFormBuilderPage/UdpQuestionFormBuilderPage.jsx"],"sourcesContent":["import React, { useCallback } from 'react';\nimport { useHistory } from 'react-router-dom';\nimport { UdpQuestionFormBuilder } from '@univerus/udp-react-stencil-component-library';\nimport { useUser } from '../../../utilities/auth/useUser';\nimport { useTenant } from '../../../utilities/tenant/useTenant';\nimport { useSnackbar } from 'notistack';\nimport { useUdpFormParameters } from '../UdpFormsUtils/Utils';\n\nconst UdpQuestionFormBuilderPage = ({ formsBaseUrlPath = '/forms', onFormCreated }) => {\n  const user = useUser();\n  const tenant = useTenant();\n  const history = useHistory();\n  const { enqueueSnackbar, closeSnackbar } = useSnackbar();\n  const { formId, formVersion } = useUdpFormParameters();\n\n  // Brand-new form just saved (POST /UdpForm/full). Transition off the\n  // `/forms/new` route to the canonical `/forms/{id}/builder` path so\n  // refresh / share / back-button all work. No `?v=` — version 1 IS the\n  // latest of a brand-new form, and \"no version param\" is the canonical\n  // \"I'm on latest\" shape. `replace` (not `push`) keeps the stale `/new`\n  // URL out of history.\n  //\n  // Arrives as a Stencil `@Event` CustomEvent: `e.detail = { formId, version }`.\n  //\n  // A host whose routes can't express path segments (e.g. query-param addressed\n  // settings pages) passes `onFormCreated` to own the transition itself; the\n  // path replace is skipped entirely in that case.\n  const handleFormCreated = useCallback(\n    (e) => {\n      const newFormId = e?.detail?.formId;\n      if (!newFormId) return;\n      if (onFormCreated) {\n        onFormCreated(newFormId, e?.detail?.version);\n        return;\n      }\n      history.replace(`${formsBaseUrlPath}/${newFormId}/builder`);\n    },\n    [history, formsBaseUrlPath, onFormCreated],\n  );\n\n  return (\n    <div>\n      <UdpQuestionFormBuilder\n        formId={formId}\n        version={formVersion}\n        history={history}\n        getUserCallback={() => user}\n        getTenantCallback={() => tenant}\n        enqueueSnackbar={enqueueSnackbar}\n        closeSnackbar={closeSnackbar}\n        onFormCreated={handleFormCreated}\n        isPublicFormConfigOn={true}\n        isCommentingConfigOn={true}\n        isFollowUpFormConfigOn={true}\n      />\n    </div>\n  );\n};\n\nexport default UdpQuestionFormBuilderPage;\n"],"mappings":";;;;;;;;;AAQA,MAAMQ,8BAA6BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,GAAA;CAAC,MAAA,EAAAC,kBAAAC,IAAAC,kBAAAL;CAAE,MAAAG,mBAAAC,OAAAE,KAAAA,IAAA,WAAAF;CACpC,MAAAG,OAAaZ,SAAS;CACtB,MAAAa,SAAeZ,WAAW;CAC1B,MAAAa,UAAgBhB,YAAY;CAC5B,MAAA,EAAAiB,iBAAAC,kBAA2Cd,aAAa;CACxD,MAAA,EAAAe,QAAAC,gBAAgCf,sBAAsB;CAAC,IAAAgB;AAAA,KAAAb,EAAA,OAAAE,oBAAAF,EAAA,OAAAQ,WAAAR,EAAA,OAAAI,eAAA;AAerDS,QAAAC,MAAA;GACE,MAAAC,YAAkBD,GAACE,QAAgBL;AACnC,OAAI,CAACI,UAAS;AACd,OAAIX,eAAa;AACfA,kBAAcW,WAAWD,GAACE,QAAiBC,QAAC;AAAA;;AAG9CT,WAAOU,QAAS,GAAGhB,iBAAgB,GAAIa,UAAS,UAAW;;AAC5Df,IAAA,KAAAE;AAAAF,IAAA,KAAAQ;AAAAR,IAAA,KAAAI;AAAAJ,IAAA,KAAAa;OAAAA,MAAAb,EAAA;CATH,MAAAmB,oBAA0BN;CAWxB,IAAAO;AAAA,KAAApB,EAAA,OAAAM,MAAA;AAQqBc,aAAMd;AAAIN,IAAA,KAAAM;AAAAN,IAAA,KAAAoB;OAAAA,MAAApB,EAAA;CAAA,IAAAqB;AAAA,K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