File: //snap/lxd/31335/share/lxd-ui/assets/CreateNetwork-2bcb2728.js
import{e as v,d as r,i as x,m as S,r as l,G as d,n as q,f as F,j as t,L as O,z as B,B as L,b as M,q as i,p as A}from"./index-58f102d5.js";import{c as I,a as R,u as $}from"./index.esm-e5155ebf.js";import{S as G}from"./updateMaxHeight-f8bf876e.js";import{c as K,a as Q}from"./networks-66b2dcb3.js";import{N as T,M as V,t as p}from"./NetworkForm-6ecbab95.js";import{y as Y,d as z}from"./instanceValidation-ef509f0a.js";import{i as D,s as E}from"./settings-c23f9009.js";import{Y as U}from"./ProfileFormMenu-727531f6.js";import"./FormMenuItem-a28b3dc4.js";import"./ConfigurationTable-c62f6ae0.js";import"./ConfigFieldDescription-05f56cf3.js";import"./AutoExpandingTextArea-08a1e7d3.js";import"./instanceConfigInheritance-e17ec51d.js";const ne=()=>{const n=v(),o=r.useNotify(),y=x(),{project:a}=S(),[f,k]=l.useState(d(V)),N=l.useState(null),{data:c,isLoading:w}=q(),m=D(c),b=E(c),{data:h=[]}=F({queryKey:[i.cluster,i.members],queryFn:A,enabled:m});if(!a)return t.jsx(t.Fragment,{children:"Missing project"});if(w)return t.jsx(O,{});const j=I().shape({name:R().test("deduplicate","A network with this name already exists",e=>B(e,a,N,"networks")).required("Network name is required")}),s=$({initialValues:{readOnly:!1,isCreating:!0,name:"",type:b?"ovn":"bridge"},validationSchema:j,onSubmit:e=>{const u=e.yaml?Y(e.yaml):p(e);(m&&e.type!=="ovn"?()=>K(u,a,h):()=>Q(u,a))().then(()=>{y.invalidateQueries({queryKey:[i.networks]}),n(`/ui/project/${a}/networks`,o.queue(o.success(`Network ${e.name} created.`)))}).catch(C=>{s.setSubmitting(!1),o.failure("Network creation failed",C)})}}),g=()=>{const e=p(s.values);return z(e)};return t.jsxs(L,{title:"Create a network",contentClassName:"create-network",children:[t.jsx(M,{}),t.jsx(T,{formik:s,getYaml:g,project:a,section:f,setSection:e=>{s.values.yaml&&e!==U&&s.setFieldValue("yaml",void 0),k(d(e))}}),t.jsxs("div",{className:"p-bottom-controls",children:[t.jsx("hr",{}),t.jsx(r.Row,{className:"u-align--right",children:t.jsxs(r.Col,{size:12,children:[t.jsx(r.Button,{appearance:"base",onClick:()=>n(`/ui/project/${a}/networks`),children:"Cancel"}),t.jsx(G,{isSubmitting:s.isSubmitting,isDisabled:!s.isValid||!s.values.name||s.values.type==="ovn"&&!s.values.network,buttonLabel:"Create",onClick:()=>void s.submitForm()})]})})]})]})};export{ne as default};