Skip to content

Commit 235fe79

Browse files
committed
refactor: packages/common 하위의 apis, schemas, utils, contexts, hooks namespace 제거
1 parent 9d7d394 commit 235fe79

74 files changed

Lines changed: 1243 additions & 1285 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/pyconkr-admin/src/components/elements/admin_signin_guard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Common from "@frontend/common";
1+
import { useBackendAdminClient, useSignedInUserQuery } from "@frontend/common/src/hooks/useAdminAPI";
22
import { CircularProgress } from "@mui/material";
33
import { ErrorBoundary, Suspense } from "@suspensive/react";
44
import * as React from "react";
@@ -9,8 +9,8 @@ import { addSnackbar } from "../../utils/snackbar";
99
export const BackendAdminSignInGuard: React.FC<{ children: React.ReactNode }> = ErrorBoundary.with(
1010
{ fallback: <>로그인 정보를 불러오는 중 문제가 발생했습니다.</> },
1111
Suspense.with({ fallback: <CircularProgress /> }, ({ children }) => {
12-
const backendAdminAPIClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
13-
const { data } = Common.Hooks.BackendAdminAPI.useSignedInUserQuery(backendAdminAPIClient);
12+
const backendAdminAPIClient = useBackendAdminClient();
13+
const { data } = useSignedInUserQuery(backendAdminAPIClient);
1414

1515
if (!data) {
1616
addSnackbar("로그인 후 이용해주세요.", "error");

apps/pyconkr-admin/src/components/layouts/admin_editor.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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";
25
import { Add, Close, Delete, Edit } from "@mui/icons-material";
36
import {
47
Box,
@@ -132,7 +135,7 @@ const fieldPropsToSelectedProps = (props: FieldProps): OutlinedSelectProps & { d
132135
};
133136

134137
const 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

170173
const 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

253256
const 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
);

apps/pyconkr-admin/src/components/layouts/admin_list.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as Common from "@frontend/common";
1+
import { Components } from "@frontend/common";
2+
import { useBackendAdminClient, useListQuery } from "@frontend/common/src/hooks/useAdminAPI";
23
import { Add } from "@mui/icons-material";
34
import { Box, Button, CircularProgress, Stack, Table, TableBody, TableCell, TableHead, TableRow, Typography } from "@mui/material";
45
import { ErrorBoundary, Suspense } from "@suspensive/react";
@@ -23,11 +24,11 @@ type ListRowType = {
2324
};
2425

2526
const InnerAdminList: React.FC<AdminListProps> = ErrorBoundary.with(
26-
{ fallback: Common.Components.ErrorFallback },
27+
{ fallback: Components.ErrorFallback },
2728
Suspense.with({ fallback: <CircularProgress /> }, ({ app, resource, hideCreatedAt, hideUpdatedAt, hideCreateNew }) => {
2829
const navigate = useNavigate();
29-
const backendAdminClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
30-
const listQuery = Common.Hooks.BackendAdminAPI.useListQuery<ListRowType>(backendAdminClient, app, resource);
30+
const backendAdminClient = useBackendAdminClient();
31+
const listQuery = useListQuery<ListRowType>(backendAdminClient, app, resource);
3132

3233
return (
3334
<Stack sx={{ flexGrow: 1, width: "100%", minHeight: "100%" }}>

apps/pyconkr-admin/src/components/pages/account/account.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import * as Common from "@frontend/common";
1+
import { Components } from "@frontend/common";
2+
import { useBackendAdminClient, useSignedInUserQuery } from "@frontend/common/src/hooks/useAdminAPI";
23
import { CircularProgress } from "@mui/material";
34
import { ErrorBoundary, Suspense } from "@suspensive/react";
45
import * as React from "react";
56
import { Navigate } from "react-router-dom";
67

78
export const AccountRedirectPage: React.FC = ErrorBoundary.with(
8-
{ fallback: Common.Components.ErrorFallback },
9+
{ fallback: Components.ErrorFallback },
910
Suspense.with({ fallback: <CircularProgress /> }, () => {
10-
const backendAdminAPIClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
11-
const { data } = Common.Hooks.BackendAdminAPI.useSignedInUserQuery(backendAdminAPIClient);
11+
const backendAdminAPIClient = useBackendAdminClient();
12+
const { data } = useSignedInUserQuery(backendAdminAPIClient);
1213

1314
return data ? <Navigate to="/account/manage" replace /> : <Navigate to="/account/sign-in" replace />;
1415
})

apps/pyconkr-admin/src/components/pages/account/manage.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import * as Common from "@frontend/common";
1+
import { useBackendAdminClient, useChangePasswordMutation, useSignOutMutation } from "@frontend/common/src/hooks/useAdminAPI";
2+
import { getFormValue, isFormValid } from "@frontend/common/src/utils";
3+
import { me } from "@frontend/common/src/apis/admin_api";
24
import { Logout } from "@mui/icons-material";
35
import { Button, Stack, Tab, Tabs, TextField, Typography } from "@mui/material";
46
import * as React from "react";
@@ -16,9 +18,9 @@ export const AccountManagementPage: React.FC = () => {
1618
const changePasswordFormRef = React.useRef<HTMLFormElement>(null);
1719
const [pageState, setPageState] = React.useState<{ tab: number }>({ tab: 0 });
1820
const navigate = useNavigate();
19-
const backendAdminAPIClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
20-
const signOutMutation = Common.Hooks.BackendAdminAPI.useSignOutMutation(backendAdminAPIClient);
21-
const changePasswordMutation = Common.Hooks.BackendAdminAPI.useChangePasswordMutation(backendAdminAPIClient);
21+
const backendAdminAPIClient = useBackendAdminClient();
22+
const signOutMutation = useSignOutMutation(backendAdminAPIClient);
23+
const changePasswordMutation = useChangePasswordMutation(backendAdminAPIClient);
2224

2325
const setTab = (_: React.SyntheticEvent, tab: number) => setPageState((ps) => ({ ...ps, tab }));
2426

@@ -37,12 +39,12 @@ export const AccountManagementPage: React.FC = () => {
3739
event.stopPropagation();
3840

3941
const form = changePasswordFormRef.current;
40-
if (!Common.Utils.isFormValid(form)) {
42+
if (!isFormValid(form)) {
4143
addSnackbar("폼에 오류가 있습니다. 다시 확인해주세요.", "error");
4244
return;
4345
}
4446

45-
const formData = Common.Utils.getFormValue<ChangePasswordFormType>({ form });
47+
const formData = getFormValue<ChangePasswordFormType>({ form });
4648
if (formData.new_password !== formData.new_password_confirm) {
4749
addSnackbar("새 비밀번호와 확인 비밀번호가 일치하지 않습니다.", "error");
4850
return;
@@ -59,7 +61,7 @@ export const AccountManagementPage: React.FC = () => {
5961

6062
React.useEffect(() => {
6163
(async () => {
62-
const userInfo = await Common.BackendAdminAPIs.me(backendAdminAPIClient)();
64+
const userInfo = await me(backendAdminAPIClient)();
6365
if (!userInfo) {
6466
addSnackbar("로그아웃 상태입니다!", "error");
6567
navigate("/");

apps/pyconkr-admin/src/components/pages/account/sign_in.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import * as Common from "@frontend/common";
1+
import { useBackendAdminClient, useSignInMutation } from "@frontend/common/src/hooks/useAdminAPI";
2+
import { getFormValue } from "@frontend/common/src/utils";
3+
import { me } from "@frontend/common/src/apis/admin_api";
24
import { Login } from "@mui/icons-material";
35
import { Button, Stack, TextField, Typography } from "@mui/material";
46
import * as React from "react";
@@ -16,14 +18,14 @@ export const SignInPage: React.FC = () => {
1618
const [pageState, setPageState] = React.useState<PageStateType>({ userJustSignedIn: false });
1719
const setUserJustSignedIn = () => setPageState((ps) => ({ ...ps, userJustSignedIn: true }));
1820

19-
const backendAdminAPIClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
20-
const signInMutation = Common.Hooks.BackendAdminAPI.useSignInMutation(backendAdminAPIClient);
21+
const backendAdminAPIClient = useBackendAdminClient();
22+
const signInMutation = useSignInMutation(backendAdminAPIClient);
2123

2224
const handleSignIn = (event: React.FormEvent<HTMLFormElement>) => {
2325
event.preventDefault();
2426
if (!formRef.current) return;
2527

26-
const formData = Common.Utils.getFormValue<{
28+
const formData = getFormValue<{
2729
identity: string;
2830
password: string;
2931
}>({ form: formRef.current });
@@ -41,7 +43,7 @@ export const SignInPage: React.FC = () => {
4143
(async () => {
4244
if (pageState.userJustSignedIn) return;
4345

44-
const userInfo = await Common.BackendAdminAPIs.me(backendAdminAPIClient)();
46+
const userInfo = await me(backendAdminAPIClient)();
4547
if (userInfo) {
4648
addSnackbar(`이미 ${userInfo.username}님으로 로그인되어 있습니다!`, "success");
4749
navigate("/");

apps/pyconkr-admin/src/components/pages/file/upload.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Common from "@frontend/common";
1+
import { useBackendAdminClient, useUploadPublicFileMutation } from "@frontend/common/src/hooks/useAdminAPI";
22
import { CloudUpload, PermMedia } from "@mui/icons-material";
33
import { Box, Button, Input, Stack, Typography } from "@mui/material";
44
import * as React from "react";
@@ -25,8 +25,8 @@ const InnerPublicFileUploadPage: React.FC = () => {
2525
});
2626
const fileInputRef = React.useRef<HTMLInputElement>(null);
2727
const fileDragBoxRef = React.useRef<HTMLDivElement>(null);
28-
const backendAdminClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
29-
const uploadPublicFileMutation = Common.Hooks.BackendAdminAPI.useUploadPublicFileMutation(backendAdminClient);
28+
const backendAdminClient = useBackendAdminClient();
29+
const uploadPublicFileMutation = useUploadPublicFileMutation(backendAdminClient);
3030

3131
const forceRerender = React.useCallback(
3232
() =>

0 commit comments

Comments
 (0)