@@ -8,26 +8,50 @@ import {
88 TextField ,
99 Typography ,
1010} from "@mui/material" ;
11+ import { useState } from "react" ;
12+ import { axios } from "../../data/axios" ;
13+ import { useNavigate } from "react-router-dom" ;
14+ import { useRecoilValue } from "recoil" ;
15+ import { appTemplateState } from "../../data/atoms" ;
16+
17+ export function AppFromTemplateDialog ( { open, setOpen, appTemplateSlug } ) {
18+ const [ appName , setAppName ] = useState ( "Untitled" ) ;
19+ const appTemplate = useRecoilValue (
20+ appTemplateState (
21+ appTemplateSlug . startsWith ( "_blank_" ) ? "_blank_" : appTemplateSlug ,
22+ ) ,
23+ ) ;
24+ const navigate = useNavigate ( ) ;
1125
12- export function AppFromTemplateDialog ( {
13- open,
14- setOpen,
15- appName,
16- setAppName,
17- createApp,
18- appTemplate,
19- } ) {
2026 const handleClose = ( ) => {
2127 setOpen ( false ) ;
2228 } ;
2329
30+ const createApp = ( ) => {
31+ const payload = {
32+ ...( appTemplate . app || { } ) ,
33+ name : appName || appTemplate ?. name || "Untitled" ,
34+ app_type : appTemplate ?. app ?. type ,
35+ type_slug :
36+ appTemplate ?. app ?. type_slug ||
37+ appTemplateSlug . replaceAll ( "_blank_" , "" ) ,
38+ template_slug : appTemplate ?. slug ,
39+ } ;
40+ axios ( )
41+ . post ( "/api/apps" , payload )
42+ . then ( ( response ) => {
43+ const appID = response . data . uuid ;
44+ navigate ( `/apps/${ appID } ` ) ;
45+ } ) ;
46+ } ;
47+
2448 return (
2549 < Dialog open = { open } onClose = { handleClose } >
2650 < DialogContent >
2751 < Typography
2852 style = { { paddingTop : 5 , fontSize : "20px" , fontWeight : 500 } }
2953 >
30- { appTemplate ?. name }
54+ { appTemplate ?. name || "Create a new App" }
3155 </ Typography >
3256 < Typography style = { { paddingTop : 10 , fontSize : "14px" , color : "#555" } } >
3357 { appTemplate ?. description }
0 commit comments