{"version":3,"file":"AddViewNote.mjs","names":["React","useRef","useState","ConfigService","UdpFluentButton","UdpAutocomplete","UdpTextarea","UdpTextInput","apiMutate","useAxiosGet","useHandleAxiosSnackbar","PageLoading","useUser","Field","Form","useTranslation","AddViewNote","props","entityBusinessKey","closeSidesheet","mode","selectedNote","setRefreshNotes","t","addingNote","setAddingNote","formSubmitRef","user","isViewing","handleSuccessSnackbar","handleErrorSnackbar","data","noteTypes","loading","noteTypesLoading","tenantV2ApiUrl","handleAddNote","formValues","fullNoteData","unityUserId","id","userDisplayName","name","method","then","resp","noteFiledForData","noteId","defaultValue","e","find","nt","code","typeCode","option","subject","content","current","handleSubmit"],"sources":["../../../../../src/udp/pages/UdpMaintenanceEnginePage/components/AddViewNote.jsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\nimport {\n  ConfigService,\n  UdpFluentButton\n} from '@univerus/udp-react-stencil-component-library';\nimport {\n  UdpAutocomplete,\n  UdpTextarea,\n  UdpTextInput\n} from '../../../../UI/fluent-web-components';\nimport {\n  apiMutate,\n  useAxiosGet,\n  useHandleAxiosSnackbar\n} from '../../../../utilities';\nimport { PageLoading } from '../../../../UI';\nimport { useUser } from '../../../../utilities/auth';\nimport { Field, Form } from '../../../../utilities/form';\nimport { useTranslation } from 'react-i18next';\n\nconst AddViewNote = (props) => {\n  const {\n    entityBusinessKey,\n    closeSidesheet,\n    mode,\n    selectedNote,\n    setRefreshNotes\n  } = props;\n\n  const { t } = useTranslation();\n  const [addingNote, setAddingNote] = useState(false);\n  const formSubmitRef = useRef();\n  const user = useUser();\n  const isViewing = mode === 'VIEW';\n  const { handleSuccessSnackbar, handleErrorSnackbar } =\n    useHandleAxiosSnackbar();\n\n  const [{ data: noteTypes, loading: noteTypesLoading }] = useAxiosGet(\n    ConfigService.tenantV2ApiUrl,\n    'UdpNoteType',\n    false,\n    false\n  );\n\n  const handleAddNote = async (formValues) => {\n    const fullNoteData = {\n      ...formValues,\n      unityUserId: user?.id,\n      userDisplayName: user?.name\n    };\n    try {\n      setAddingNote(true);\n      await apiMutate(\n        ConfigService.tenantV2ApiUrl,\n        'UdpNote',\n        { method: 'post' },\n        { data: fullNoteData }\n      ).then(async (resp) => {\n        if (resp?.data?.id) {\n          const noteFiledForData = {\n            noteId: resp?.data?.id,\n            entityBusinessKey: entityBusinessKey\n          };\n          await apiMutate(\n            ConfigService.tenantV2ApiUrl,\n            'UdpNoteFiledFor',\n            { method: 'post' },\n            { data: noteFiledForData }\n          ).then( () => {\n            setRefreshNotes(true)\n            handleSuccessSnackbar(\n              t('notes.snackbar.added', {\n                defaultValue: 'Note has been added successfully'\n              })\n            )\n          })\n        }\n      });\n    } catch (e) {\n      handleErrorSnackbar(\n        e,\n        t('notes.errors.addFailed', { defaultValue: 'Unable to add note.' })\n      );\n    } finally {\n      setAddingNote(false);\n      closeSidesheet();\n    }\n  };\n\n  return noteTypesLoading ? (\n    <PageLoading />\n  ) : (\n    <>\n      <Form onSubmit={handleAddNote} ref={formSubmitRef}>\n        <Field\n          component={UdpAutocomplete}\n          name='typeCode'\n          label={t('notes.form.noteType', { defaultValue: 'Note Type' })}\n          appearance='outline'\n          initialValue={\n            noteTypes?.find((nt) => nt?.code === selectedNote?.typeCode)?.name\n          }\n          options={noteTypes}\n          optionLabel={'name'}\n          optionValue={'code'}\n          parse={(option) => option?.code}\n          required={true}\n          disabled={addingNote || isViewing}\n        />\n\n        <Field\n          name='subject'\n          label={t('notes.form.subject', { defaultValue: 'Subject' })}\n          component={UdpTextInput}\n          appearance='outline'\n          initialValue={selectedNote?.subject}\n          required={true}\n          disabled={addingNote || isViewing}\n        />\n\n        <Field\n          name='content'\n          label={t('notes.form.details', { defaultValue: 'Details' })}\n          component={UdpTextarea}\n          appearance='outline'\n          initialValue={selectedNote?.content}\n          onChange={(e) => {}}\n          autoResize={true}\n          required={true}\n          disabled={addingNote || isViewing}\n        />\n      </Form>\n      {!isViewing && (\n        <UdpFluentButton\n          appearance='primary'\n          slot='footer'\n          onClick={() => formSubmitRef.current?.handleSubmit()}\n          disabled={addingNote}\n        >\n          {t('common.add', { defaultValue: 'Add' })}\n        </UdpFluentButton>\n      )}\n    </>\n  );\n};\n\nexport default AddViewNote;\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAMgB,eAAeC,UAAU;CAC7B,MAAM,EACJC,mBACAC,gBACAC,MACAC,cACAC,oBACEL;CAEJ,MAAM,EAAEM,MAAMR,gBAAgB;CAC9B,MAAM,CAACS,YAAYC,iBAAiBvB,SAAS,MAAM;CACnD,MAAMwB,gBAAgBzB,QAAQ;CAC9B,MAAM0B,OAAOf,SAAS;CACtB,MAAMgB,YAAYR,SAAS;CAC3B,MAAM,EAAES,uBAAuBC,wBAC7BpB,wBAAwB;CAE1B,MAAM,CAAC,EAAEqB,MAAMC,WAAWC,SAASC,sBAAsBzB,YACvDN,cAAcgC,gBACd,eACA,OACA,MACD;CAED,MAAMC,gBAAgB,OAAOC,eAAe;EAC1C,MAAMC,eAAe;GACnB,GAAGD;GACHE,aAAaZ,MAAMa;GACnBC,iBAAiBd,MAAMe;GACxB;AACD,MAAI;AACFjB,iBAAc,KAAK;AACnB,SAAMjB,UACJL,cAAcgC,gBACd,WACA,EAAEQ,QAAQ,QAAQ,EAClB,EAAEZ,MAAMO,cACV,CAAC,CAACM,KAAK,OAAOC,SAAS;AACrB,QAAIA,MAAMd,MAAMS,IAAI;KAClB,MAAMM,mBAAmB;MACvBC,QAAQF,MAAMd,MAAMS;MACDtB;MACpB;AACD,WAAMV,UACJL,cAAcgC,gBACd,mBACA,EAAEQ,QAAQ,QAAQ,EAClB,EAAEZ,MAAMe,kBACV,CAAC,CAACF,WAAY;AACZtB,sBAAgB,KAAK;AACrBO,4BACEN,EAAE,wBAAwB,EACxByB,cAAc,oCACf,CACH,CAAC;OACD;;KAEJ;WACKC,GAAG;AACVnB,uBACEmB,GACA1B,EAAE,0BAA0B,EAAEyB,cAAc,uBAAuB,CACrE,CAAC;YACO;AACRvB,iBAAc,MAAM;AACpBN,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