import{f as j,d as m,k as h,l as x,r as u,J as c,o as C,au as N,j as e,a$ as F,c as q,b0 as V,q as r}from"./index-DRe7Uehz.js";import{c as $,a as b}from"./index.esm-9c567zNd.js";import{N as k}from"./NotificationRow-DDCUSSQc.js";import{B as P}from"./BaseLayout-uhDucFhR.js";import{M as T,v as B,a as K}from"./StorageVolumeForm-HwAhlze4.js";import{P as O}from"./StorageVolumesFilter-Crs7SCUb.js";import{F as Q}from"./FormFooterLayout-DzEn1tAf.js";import{R}from"./ResourceLink-DsyYS3_L.js";import"./FormMenuItem-Drov6ZdA.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-BsPKhbuP.js";import"./AutoExpandingTextArea-CM-5O8_l.js";import"./ScrollableTable-tzQTcMDf.js";import"./formFields-BDRvqvBI.js";import"./snapshots-Ch4qmIVo.js";import"./DiskSizeSelector-Chdtob2H.js";import"./StoragePoolSelector-DIilWoZt.js";import"./CustomSelect-BB1pXqeO.js";import"./StoragePoolSize-LK8V_koD.js";import"./searchAndFilter-BEZtSWxl.js";import"./ScrollableContainer-i2n9yzu7.js";import"./ResourceIcon-iakkHkJJ.js";const re=()=>{const n=j(),l=m.useNotify(),p=h(),a=x(),[d,y]=u.useState(c(T)),f=u.useState(null),{project:t}=C(),[g]=N();if(!t)return e.jsx(e.Fragment,{children:"Missing project"});const v=$().shape({name:b().test(...F(t,"custom",f)).required("This field is required")}),s=q({initialValues:{content_type:"filesystem",volumeType:"custom",name:"",project:t,pool:g.get(O)||"",size:"GiB",readOnly:!1,isCreating:!0,entityType:"storageVolume"},validationSchema:v,onSubmit:o=>{const S=B(o,t);V(o.pool,t,S).then(()=>{a.invalidateQueries({queryKey:[r.storage]}),a.invalidateQueries({queryKey:[r.customVolumes,t]}),a.invalidateQueries({queryKey:[r.projects,t]}),a.invalidateQueries({predicate:i=>i.queryKey[0]===r.volumes}),n(`/ui/project/${t}/storage/volumes`),p.success(e.jsxs(e.Fragment,{children:["Storage volume"," ",e.jsx(R,{type:"volume",value:o.name,to:`/ui/project/${t}/storage/pool/${o.pool}/volumes/custom/${o.name}`})," ","created."]}))}).catch(i=>{s.setSubmitting(!1),l.failure("Storage volume creation failed",i)})}});return e.jsxs(P,{title:"Create volume",contentClassName:"storage-volume-form",children:[e.jsx(k,{}),e.jsx(K,{formik:s,section:d,setSection:o=>y(c(o))}),e.jsxs(Q,{children:[e.jsx(m.Button,{appearance:"base",onClick:()=>n(`/ui/project/${t}/storage/volumes`),children:"Cancel"}),e.jsx(m.ActionButton,{appearance:"positive",loading:s.isSubmitting,disabled:!s.isValid,onClick:()=>void s.submitForm(),children:"Create"})]})]})};export{re as default};
