{"version":3,"file":"AddSettingsProfile-abd8c215.js","sources":["../../src/components/SettingsProfiles/AddSettingsProfile.tsx"],"sourcesContent":["import { useState } from \"react\"\nimport styled from \"styled-components\"\n\nimport { HOMEPROFILES_LIMIT_LIST } from \"src/data/homeProfiles/logic/homeProfileConstants\"\nimport { profileNameCopy } from \"src/data/homeProfiles/logic/homeProfiles\"\nimport {\n useFetchProfiles,\n usePostProfile,\n} from \"src/data/homeProfiles/queries/HomeProfilesQueries\"\nimport { TProfileState } from \"src/data/homeProfiles/types/homeProfilesTypes\"\nimport { useOrganization } from \"src/data/organizations/hooks/useOrganization\"\nimport { useFetchOrganizations } from \"src/data/organizations/queries/organizationQueries\"\nimport { IOrganization } from \"src/data/organizations/types/organizationTypes\"\nimport { langKeys } from \"src/i18n/langKeys\"\nimport { useTranslate } from \"src/i18n/useTranslate\"\nimport { Routes } from \"src/router/routes\"\nimport { useRouter } from \"src/router/useRouter\"\nimport { MButton } from \"src/ui/Button/MButton\"\nimport { InternalLink } from \"src/ui/Link/InternalLink\"\nimport { MBanner } from \"src/ui/MBanner/MBanner\"\nimport { MCircularProgress } from \"src/ui/MCircularProgress/MCircularProgress\"\nimport { MSelect } from \"src/ui/MSelect/MSelect\"\nimport { MText } from \"src/ui/MText\"\nimport { MTextField } from \"src/ui/MTextField/MTextField\"\nimport { spacing } from \"src/ui/spacing\"\n\nexport function AddSettingsProfile() {\n const { t } = useTranslate()\n const { navigate } = useRouter()\n\n const { org } = useOrganization()\n const [templateId, setTemplateId] = useState(undefined)\n const [name, setName] = useState(\"\")\n const fetchOrganizations = useFetchOrganizations()\n const postProfile = usePostProfile()\n\n const fetchProfiles = useFetchProfiles({\n orgId: org?.id,\n filter: { limit: HOMEPROFILES_LIMIT_LIST, offset: 0 },\n options: {\n onSuccess: (data) => {\n setTemplateId(data.profiles[0]?.id)\n },\n },\n })\n const profiles: TProfileState = fetchProfiles.data?.profiles || []\n const profilesCount = fetchProfiles.data?.paging.total_count || 0\n\n function handleSave(organization: IOrganization | null) {\n if (!organization) {\n throw Error(\"Active team is undefined\")\n }\n const body = {\n copy_from_profile_id: templateId,\n organization_id: organization.id,\n name,\n }\n postProfile.mutate(body, {\n onSuccess: (profile) => {\n navigate(Routes.MonitoringSettingEdit.location(profile.id).pathname)\n },\n })\n }\n\n function handleChangeTemplate(id: string) {\n setTemplateId(id)\n\n const profileTemplate = profiles.find((p) => p.id === id)\n setName(profileNameCopy(profileTemplate?.name))\n }\n\n if (fetchProfiles.isInitialLoading) {\n return (\n \n
\n {t(langKeys.profiles_create_header)}\n {t(langKeys.profiles_create_description)}\n
\n
\n \n
\n
\n )\n }\n\n if (fetchOrganizations.isError) {\n return (\n \n {t(langKeys.profiles_create_header)}\n {t(langKeys.profiles_create_description)}\n \n {t(langKeys.failed_something_went_wrong)}\n \n \n )\n }\n\n return (\n \n
\n {t(langKeys.profiles_create_header)}\n {t(langKeys.profiles_create_description)}\n
\n\n {profilesCount > 1 && (\n ({\n label: profile.name,\n value: profile.id,\n })),\n ]}\n onChange={handleChangeTemplate}\n />\n )}\n\n \n\n {postProfile.isError && (\n \n {t(langKeys.failed_something_went_wrong)}\n \n )}\n\n \n \n {t(langKeys.cancel)}\n \n\n {\n handleSave(org)\n }}\n loading={postProfile.isLoading}\n disabled={!name}\n >\n {t(langKeys.save)}\n \n \n
\n )\n}\n\nconst Title = styled(MText).attrs(() => ({\n variant: \"heading1\",\n marginBottom: spacing.XS,\n}))`\n margin-bottom: ${spacing.XS};\n`\n\nconst ContentBox = styled.div`\n display: grid;\n grid-row-gap: 1rem;\n max-width: 48ch;\n width: 100%;\n margin: ${spacing.XL} auto;\n`\n\nconst ActionBox = styled.div`\n display: flex;\n place-content: center space-between;\n`\n\nconst Description = styled(MText).attrs(() => ({\n variant: \"body\",\n marginBottom: spacing.L,\n}))``\n"],"names":["AddSettingsProfile","t","useTranslate","navigate","useRouter","org","useOrganization","templateId","setTemplateId","useState","undefined","name","setName","fetchOrganizations","useFetchOrganizations","postProfile","usePostProfile","fetchProfiles","useFetchProfiles","orgId","id","filter","limit","HOMEPROFILES_LIMIT_LIST","offset","options","onSuccess","data","profiles","profilesCount","paging","total_count","handleSave","organization","Error","body","copy_from_profile_id","organization_id","mutate","profile","Routes","MonitoringSettingEdit","location","pathname","handleChangeTemplate","profileTemplate","find","p","profileNameCopy","isInitialLoading","ContentBox","div","Title","langKeys","profiles_create_header","Description","profiles_create_description","style","margin","MCircularProgress","size","isError","MBanner","fullWidth","type","failed_something_went_wrong","_jsx","MSelect","label","profiles_create_based_on_title","value","hidden","map","onChange","MTextField","required","ActionBox","InternalLink","to","MonitoringSettings","cancel","MButton","onClick","loading","isLoading","disabled","save","styled","MText","attrs","variant","marginBottom","spacing","XS","XL","L"],"mappings":"gOA0BO,SAASA,GAAAA,CACR,KAAA,CAAEC,GAAMC,IACR,CAAEC,SAAAA,GAAaC,IAEf,CAAEC,IAAAA,GAAQC,IACV,CAACC,EAAYC,CAAc,EAAGC,EAAAA,SAA6BC,MAAAA,EAC3D,CAACC,EAAMC,CAAQ,EAAGH,WAAS,EAAA,EAC3BI,EAAqBC,IACrBC,EAAcC,IAEdC,EAAgBC,EAAiB,CACrCC,MAAOd,GAAKe,GACZC,OAAQ,CAAEC,MAAOC,EAAyBC,OAAQ,CAAE,EACpDC,QAAS,CACPC,UAAYC,GAAAA,CACVnB,EAAcmB,EAAKC,SAAS,CAAA,GAAIR,EAAAA,CAClC,CACF,CAAA,CACF,EACMQ,EAA0BX,EAAcU,MAAMC,UAAY,CAAA,EAC1DC,EAAgBZ,EAAcU,MAAMG,OAAOC,aAAe,EAEhE,SAASC,EAAWC,EAAkC,CACpD,GAAI,CAACA,EACH,MAAMC,MAAM,0BAAA,EAEd,MAAMC,EAAO,CACXC,qBAAsB7B,EACtB8B,gBAAiBJ,EAAab,GAC9BT,KAAAA,CAAAA,EAEFI,EAAYuB,OAAOH,EAAM,CACvBT,UAAYa,GAAAA,CACVpC,EAASqC,EAAOC,sBAAsBC,SAASH,EAAQn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