@@ -6,8 +6,13 @@ import {useDebounce} from "../utils/useDebounce.ts";
66import { determineSorting } from "../utils/sorting.ts" ;
77import * as Dialog from "@radix-ui/react-dialog" ;
88import { IconButton } from "../components/IconButton.tsx" ;
9- import { ChevronLeft , ChevronRight , Eye , Trash2 , FileStack } from "lucide-react" ;
9+ import { ChevronLeft , ChevronRight , Eye , Trash2 , FileStack , PlusIcon } from "lucide-react" ;
1010import { SearchField } from "../components/SearchField.tsx" ;
11+ import { useForm } from "react-hook-form" ;
12+
13+ type PadCreateProps = {
14+ padName : string
15+ }
1116
1217export const PadPage = ( ) => {
1318 const settingsSocket = useStore ( state => state . settingsSocket )
@@ -25,6 +30,8 @@ export const PadPage = ()=>{
2530 const [ deleteDialog , setDeleteDialog ] = useState < boolean > ( false )
2631 const [ errorText , setErrorText ] = useState < string | null > ( null )
2732 const [ padToDelete , setPadToDelete ] = useState < string > ( '' )
33+ const [ createPadDialogOpen , setCreatePadDialogOpen ] = useState < boolean > ( false )
34+ const { register, handleSubmit} = useForm < PadCreateProps > ( )
2835 const pages = useMemo ( ( ) => {
2936 if ( ! pads ) {
3037 return 0 ;
@@ -70,8 +77,33 @@ export const PadPage = ()=>{
7077 } )
7178 } )
7279
80+ type SettingsSocketCreateReponse = {
81+ error : string
82+ } | {
83+ success : string
84+ }
85+
86+ settingsSocket . on ( 'results:createPad' , ( rep : SettingsSocketCreateReponse ) => {
87+ if ( 'error' in rep ) {
88+ useStore . getState ( ) . setToastState ( {
89+ open : true ,
90+ title : rep . error ,
91+ success : false
92+ } )
93+ } else {
94+ useStore . getState ( ) . setToastState ( {
95+ open : true ,
96+ title : rep . success ,
97+ success : true
98+ } )
99+ setCreatePadDialogOpen ( false )
100+ // reload pads
101+ settingsSocket . emit ( 'padLoad' , searchParams )
102+ }
103+ } )
104+
73105 settingsSocket . on ( 'results:cleanupPadRevisions' , ( data ) => {
74- let newPads = useStore . getState ( ) . pads ?. results ?? [ ]
106+ const newPads = useStore . getState ( ) . pads ?. results ?? [ ]
75107
76108 if ( data . error ) {
77109 setErrorText ( data . error )
@@ -99,6 +131,12 @@ export const PadPage = ()=>{
99131 settingsSocket ?. emit ( 'cleanupPadRevisions' , padID )
100132 }
101133
134+ const onPadCreate = ( data : PadCreateProps ) => {
135+ settingsSocket ?. emit ( 'createPad' , {
136+ padName : data . padName
137+ } )
138+ }
139+
102140
103141 return < div >
104142 < Dialog . Root open = { deleteDialog } > < Dialog . Portal >
@@ -139,7 +177,32 @@ export const PadPage = ()=>{
139177 </ Dialog . Content >
140178 </ Dialog . Portal >
141179 </ Dialog . Root >
142- < h1 > < Trans i18nKey = "ep_admin_pads:ep_adminpads2_manage-pads" /> </ h1 >
180+ < Dialog . Root open = { createPadDialogOpen } >
181+ < Dialog . Portal >
182+ < Dialog . Overlay className = "dialog-confirm-overlay" />
183+ < Dialog . Content className = "dialog-confirm-content" >
184+ < Dialog . Title className = "dialog-confirm-title" > < Trans i18nKey = "index.newPad" /> </ Dialog . Title >
185+ < form onSubmit = { handleSubmit ( onPadCreate ) } >
186+ < button className = "dialog-close-button" onClick = { ( ) => {
187+ setCreatePadDialogOpen ( false ) ;
188+ } } > x</ button >
189+ < div style = { { display : 'grid' , gap : '10px' , gridTemplateColumns : 'auto auto' , marginBottom : '1rem' } } >
190+ < label > < Trans i18nKey = "ep_admin_pads:ep_adminpads2_padname" /> </ label >
191+ < input { ...register ( 'padName' , {
192+ required : true
193+ } ) } />
194+ </ div >
195+ < input type = "submit" value = { t ( 'admin_settings.createPad' ) } className = "login-button" />
196+ </ form >
197+ </ Dialog . Content >
198+ </ Dialog . Portal >
199+ </ Dialog . Root >
200+ < span className = "manage-pads-header" >
201+ < h1 > < Trans i18nKey = "ep_admin_pads:ep_adminpads2_manage-pads" /> </ h1 >
202+ < span style = { { width : '29px' , marginBottom : 'auto' , marginTop : 'auto' , flexGrow : 1 } } > < IconButton style = { { float : 'right' } } icon = { < PlusIcon /> } title = { < Trans i18nKey = "index.newPad" /> } onClick = { ( ) => {
203+ setCreatePadDialogOpen ( true )
204+ } } /> </ span >
205+ </ span >
143206 < SearchField value = { searchTerm } onChange = { v => setSearchTerm ( v . target . value ) } placeholder = { t ( 'ep_admin_pads:ep_adminpads2_search-heading' ) } />
144207 < table >
145208 < thead >
0 commit comments