1- import * as Common from "@frontend/common" ;
1+ import { Components } from "@frontend/common" ;
2+ import { useBackendAdminClient , useCreateMutation , useRemoveMutation , useSchemaQuery , useUpdateMutation } from "@frontend/common/src/hooks/useAdminAPI" ;
3+ import { filterPropertiesByLanguageInJsonSchema , filterReadOnlyPropertiesInJsonSchema , filterWritablePropertiesInJsonSchema } from "@frontend/common/src/utils" ;
4+ import { retrieve } from "@frontend/common/src/apis/admin_api" ;
25import { Add , Close , Delete , Edit } from "@mui/icons-material" ;
36import {
47 Box ,
@@ -132,7 +135,7 @@ const fieldPropsToSelectedProps = (props: FieldProps): OutlinedSelectProps & { d
132135} ;
133136
134137const M2MSelect : Field = ErrorBoundary . with (
135- { fallback : Common . Components . ErrorFallback } ,
138+ { fallback : Components . ErrorFallback } ,
136139 Suspense . with ( { fallback : < CircularProgress /> } , ( props ) => {
137140 const selectable = ( props . schema . items as JSONSchema7 ) . oneOf as DescriptedEnum [ ] ;
138141 const selectableListObj : DescriptedEnumObject = selectable . reduce ( ( a , i ) => ( { ...a , [ i . const ] : i } ) , { } as DescriptedEnumObject ) ;
@@ -168,7 +171,7 @@ const MDRendererContainer = styled(Box)(({ theme }) => ({
168171} ) ) ;
169172
170173const MDEditorField : Field = ErrorBoundary . with (
171- { fallback : Common . Components . ErrorFallback } ,
174+ { fallback : Components . ErrorFallback } ,
172175 ( { disabled, formData, name, onChange : rawOnChange } ) => {
173176 const [ valueState , setValueState ] = React . useState < string | undefined > ( formData ?. toString ( ) || "" ) ;
174177 const onChange = ( value ?: string ) => {
@@ -180,10 +183,10 @@ const MDEditorField: Field = ErrorBoundary.with(
180183 < Typography variant = "subtitle2" component = "legend" children = { name } />
181184 < Stack direction = "row" spacing = { 2 } sx = { { width : "100%" , height : "100%" , minHeight : "100%" , maxHeight : "100%" , flexGrow : 1 , py : 2 } } >
182185 < Box sx = { { width : "50%" , maxWidth : "50%" } } >
183- < Common . Components . MarkdownEditor disabled = { disabled } name = { name } value = { valueState } onChange = { onChange } extraCommands = { [ ] } />
186+ < Components . MarkdownEditor disabled = { disabled } name = { name } value = { valueState } onChange = { onChange } extraCommands = { [ ] } />
184187 </ Box >
185188 < MDRendererContainer >
186- < Common . Components . MDXRenderer text = { valueState || "" } format = "md" />
189+ < Components . MDXRenderer text = { valueState || "" } format = "md" />
187190 </ MDRendererContainer >
188191 </ Stack >
189192 </ MUIStyledFieldset >
@@ -234,7 +237,7 @@ const ReadOnlyValueField: React.FC<{
234237 ) }
235238 { fieldState . blob . type . startsWith ( "application/json" ) && fieldState . blobText && (
236239 < Box sx = { { maxWidth : "600px" , overflow : "auto" } } >
237- < Common . Components . LottieDebugPanel data = { JSON . parse ( fieldState . blobText ) } />
240+ < Components . LottieDebugPanel data = { JSON . parse ( fieldState . blobText ) } />
238241 </ Box >
239242 ) }
240243 < a href = { value as string } > 링크</ a >
@@ -251,7 +254,7 @@ type InnerAdminEditorStateType = {
251254} ;
252255
253256const InnerAdminEditor : React . FC < AppResourceIdType & AdminEditorPropsType > = ErrorBoundary . with (
254- { fallback : Common . Components . ErrorFallback } ,
257+ { fallback : Components . ErrorFallback } ,
255258 Suspense . with (
256259 { fallback : < CircularProgress /> } ,
257260 ( {
@@ -275,18 +278,18 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
275278 tab : 0 ,
276279 formData : undefined ,
277280 } ) ;
278- const backendAdminClient = Common . Hooks . BackendAdminAPI . useBackendAdminClient ( ) ;
279- const { data : schemaInfo } = Common . Hooks . BackendAdminAPI . useSchemaQuery ( backendAdminClient , app , resource ) ;
281+ const backendAdminClient = useBackendAdminClient ( ) ;
282+ const { data : schemaInfo } = useSchemaQuery ( backendAdminClient , app , resource ) ;
280283
281284 const setTab = ( _ : React . SyntheticEvent , tab : number ) => setEditorState ( ( ps ) => ( { ...ps , tab } ) ) ;
282285 const setFormData = ( formData ?: Record < string , string > ) => setEditorState ( ( ps ) => ( { ...ps , formData } ) ) ;
283286 const appendFormDataState = ( data ?: Record < string , string > ) => setEditorState ( ( ps ) => ( { ...ps , formData : { ...ps . formData , ...data } } ) ) ;
284287 const selectedLanguage = editorState . tab === 0 ? "ko" : "en" ;
285288 const notSelectedLanguage = editorState . tab === 0 ? "en" : "ko" ;
286289
287- const createMutation = Common . Hooks . BackendAdminAPI . useCreateMutation < Record < string , string > > ( backendAdminClient , app , resource ) ;
288- const modifyMutation = Common . Hooks . BackendAdminAPI . useUpdateMutation < Record < string , string > > ( backendAdminClient , app , resource , id || "" ) ;
289- const deleteMutation = Common . Hooks . BackendAdminAPI . useRemoveMutation ( backendAdminClient , app , resource , id || "undefined" ) ;
290+ const createMutation = useCreateMutation < Record < string , string > > ( backendAdminClient , app , resource ) ;
291+ const modifyMutation = useUpdateMutation < Record < string , string > > ( backendAdminClient , app , resource , id || "" ) ;
292+ const deleteMutation = useRemoveMutation ( backendAdminClient , app , resource , id || "undefined" ) ;
290293 const submitMutation = id ? modifyMutation : createMutation ;
291294
292295 React . useEffect ( ( ) => {
@@ -296,7 +299,7 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
296299 return ;
297300 }
298301
299- const initialData = await Common . BackendAdminAPIs . retrieve < Record < string , string > > ( backendAdminClient , app , resource , id ) ( ) ;
302+ const initialData = await retrieve < Record < string , string > > ( backendAdminClient , app , resource , id ) ( ) ;
300303 setFormData ( { ...initialData , ...context } ) ;
301304 } ) ( ) ;
302305 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -344,13 +347,13 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
344347 . reduce ( ( acc , [ key , value ] ) => ( { ...acc , [ key ] : value } ) , { } as RJSFSchema ) ;
345348 }
346349
347- const writableSchema = Common . Utils . filterPropertiesByLanguageInJsonSchema (
348- Common . Utils . filterWritablePropertiesInJsonSchema ( schemaInfo . schema ) ,
350+ const writableSchema = filterPropertiesByLanguageInJsonSchema (
351+ filterWritablePropertiesInJsonSchema ( schemaInfo . schema ) ,
349352 schemaInfo . translation_fields ,
350353 selectedLanguage
351354 ) ;
352- const readOnlySchema = Common . Utils . filterPropertiesByLanguageInJsonSchema (
353- Common . Utils . filterReadOnlyPropertiesInJsonSchema ( schemaInfo . schema ) ,
355+ const readOnlySchema = filterPropertiesByLanguageInJsonSchema (
356+ filterReadOnlyPropertiesInJsonSchema ( schemaInfo . schema ) ,
354357 schemaInfo . translation_fields ,
355358 selectedLanguage
356359 ) ;
0 commit comments