Your IP : 216.73.216.52


Current Path : /snap/lxd/38768/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38768/share/lxd-ui/assets/CreateProject-Dsl6UW8t.js

import{c as C,d as o,v as R,r as c,a6 as m,V as b,u as F,ae as N,f as $,h as D,a9 as E,k as T,af as A,ag as B,ah as L,ai as O,aj as q,R as j,x as z,j as t,a3 as H}from"./index-BsQN_SZU.js";import{P as I,n as U,d as V,i as J,c as K,r as Q,p as G,a as M,b as Z}from"./ProjectForm-DrdaiE90.js";import{B as W}from"./BaseLayout-D3ZT4TU8.js";import{F as X}from"./FormFooterLayout-CcbL_-PB.js";import{P as Y}from"./ProjectRichChip-DZzjTfq6.js";import"./SshKeyForm-BNz7yPwa.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./snapshots-LtzKNDw1.js";import"./StoragePoolSelector-Bvqvds5t.js";import"./StoragePoolSize-BNbqTfwA.js";import"./Meter-cq8smrSm.js";import"./NetworkSelector-DuJmwRYk.js";import"./useNetworks-1j5RF-bH.js";import"./DiskSizeSelector-C9kWj54D.js";import"./useClusterGroups-BmTnhLw-.js";const he=()=>{const i=C(),p=o.useNotify(),f=o.useToastNotification(),y=R(),_=c.useState(null),[u,h]=c.useState(m(I)),{hasProjectsNetworksZones:g,hasStorageBuckets:P}=b(),{isFineGrained:k}=F(),{data:s}=N("default","default"),S=$().shape({name:D().test("deduplicate","A project with this name already exists",async e=>E(e,"",_,"projects")).required()}),l=()=>{H("form-contents","p-bottom-controls")};c.useEffect(l,[p.notification?.message,u]),o.useListener(window,l,"resize",!0);const d=e=>{i(`${j}/ui/project/${encodeURIComponent(e.name)}/instances`),f.success(t.jsxs(t.Fragment,{children:["Project"," ",t.jsx(Y,{projectName:e.name,urlSuffix:"/instances"})," ","created."]}))},a=T({initialValues:{name:"",restricted:!1,readOnly:!1,entityType:"project",default_instance_storage_pool:s?B(s):"",default_project_network:s?A(s):"",features_images:!0,features_profiles:!0,features_networks:!1,features_networks_zones:!1,features_storage_buckets:!0,features_storage_volumes:!0},enableReinitialize:!0,validationSchema:S,onSubmit:e=>{const w=e.restricted?{...K(e),...J(e),...V(e),...U(e)}:{};g||(e.features_networks_zones=void 0),P||(e.features_storage_buckets=void 0);const n=e.default_project_network!=="none";L(JSON.stringify({...M(e),config:{...G(e),...Q(e),...w}})).then(async()=>{if(!e.default_instance_storage_pool&&!n||e.features_profiles===!1){d(e);return}const r=await O("default",e.name,k);r.devices={root:{path:"/",pool:e.default_instance_storage_pool,type:"disk"},...n&&{eth0:{name:"eth0",network:e.default_project_network,type:"nic"}}},q(r,e.name).then(()=>{d(e)}).catch(x=>{i(`${j}/ui/project/${encodeURIComponent(e.name)}/instances`),f.failure(`Successfully created ${e.name} project. Failed to attach storage pool${n?" and network":""}.`,x)})}).catch(r=>{a.setSubmitting(!1),p.failure("Project creation failed",r)}).finally(()=>{y.invalidateQueries({queryKey:[z.projects]})})}});return t.jsxs(W,{title:"Create a project",contentClassName:"create-project",children:[t.jsx(Z,{formik:a,section:u,updateSection:e=>{h(m(e))},isEdit:!1}),t.jsxs(X,{children:[t.jsx(o.Button,{appearance:"base",onClick:async()=>i(-1),children:"Cancel"}),t.jsx(o.ActionButton,{appearance:"positive",loading:a.isSubmitting,disabled:!a.isValid||a.isSubmitting||!a.values.name,onClick:()=>{a.submitForm()},children:"Create"})]})]})};export{he as default};