@baseplate-dev/project-builder-web
Version:
Web interface for constructing project builder JSON
3 lines (2 loc) • 2.42 kB
JavaScript
import{i}from"./_virtual___federation_fn_import-C4el_tlG.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{s as v,l as D}from"./index-BsqYBobW.js";import{b as k}from"./index.esm-C5MSuOl4.js";import{w as A}from"./words-Cs2RBKRm.js";import{s as S}from"./sortBy-C9bvycg5.js";function N(r){const n=A(r.trim());let a="";for(let s=0;s<n.length;s++){const o=n[s];a&&(a+=" "),a+=o[0].toUpperCase()+o.slice(1).toLowerCase()}return a}const{appEntityType:b,baseAppSchema:F}=await i("@baseplate-dev/project-builder-lib"),{useProjectDefinition:I}=await i("@baseplate-dev/project-builder-lib/web"),{Button:h,Dialog:T,DialogContent:B,DialogDescription:O,DialogFooter:$,DialogHeader:E,DialogTitle:P,DialogTrigger:W,InputFieldController:H,SelectFieldController:L,useControlledState:M}=await i("@baseplate-dev/ui-components"),{useNavigate:R}=await i("@tanstack/react-router");function K({children:r,open:n,onOpenChange:a}){const[s,o]=M(n,a,!1),{saveDefinitionWithFeedback:f,isSavingDefinition:p}=I(),g=R(),{control:l,handleSubmit:w,reset:c}=k({resolver:v(F),defaultValues:{id:"",name:"",type:"backend"}}),j=[{label:"Backend App",value:"backend"},{label:"Web App",value:"web"}],y=w(t=>{const m=b.generateNewId();return f(u=>{const C=[...u.apps,{...t,id:m,...t.type==="web"&&{title:N(t.name),description:`A ${t.type} application`}}];u.apps=S(C,[x=>x.name])},{successMessage:`Successfully created ${t.name}!`,onSuccess:()=>{o(!1),c(),g({to:`/apps/edit/${b.keyFromId(m)}`}).catch(D)}})}),d=t=>{o(t),t||c()};return e.jsxs(T,{open:s,onOpenChange:d,children:[e.jsx(W,{asChild:!0,children:r}),e.jsxs(B,{className:"sm:max-w-md",children:[e.jsxs(E,{children:[e.jsx(P,{children:"Create New App"}),e.jsx(O,{children:"Create a new application in your project. Choose the type that best fits your needs."})]}),e.jsxs("form",{onSubmit:t=>(t.stopPropagation(),y(t)),className:"space-y-4",children:[e.jsx(H,{label:"Name",control:l,name:"name",placeholder:"e.g. backend, web, admin",description:"The name of the app, such as 'backend' or 'web'",autoComplete:"off"}),e.jsx(L,{label:"Type",control:l,name:"type",options:j,description:"Backend apps provide APIs, web apps are client applications"}),e.jsxs($,{children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>{d(!1)},children:"Cancel"}),e.jsx(h,{type:"submit",disabled:p,children:p?"Creating...":"Create App"})]})]})]})]})}export{K as N};
//# sourceMappingURL=new-app-dialog-DNFClapi.js.map