-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
868 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { SelectRef } from '@channel.io/bezier-react' | ||
import { Select as BaseSelect, ListItem } from '@channel.io/bezier-react' | ||
import type { ReactNode } from 'react' | ||
import { useEffect, useMemo, useRef, useState } from 'react' | ||
|
||
export type SelectItem<V extends string> = { | ||
leftContent?: ReactNode | ||
label: string | ||
value: V | ||
} | ||
|
||
interface SelectProps<V extends string> { | ||
items: SelectItem<V>[] | ||
value: V | ||
name?: string | ||
defaultValue?: V | ||
placeholder?: string | ||
onChange: (event: { target: { name?: string; value: V } }) => void | ||
} | ||
|
||
export function Select<V extends string>({ | ||
items, | ||
value, | ||
name, | ||
defaultValue, | ||
placeholder, | ||
onChange, | ||
}: SelectProps<V>) { | ||
const selectRef = useRef<SelectRef>(null) | ||
const [valueState, setValueState] = useState<V | undefined>(defaultValue) | ||
|
||
useEffect( | ||
function updateValueStateWhenValueChanged() { | ||
setValueState(value) | ||
}, | ||
[value] | ||
) | ||
|
||
const handleClickItem = (item: SelectItem<V>) => { | ||
selectRef.current?.handleHideDropdown() | ||
onChange?.({ target: { name, value: item.value } }) | ||
} | ||
|
||
const selectedItem = useMemo( | ||
() => items.find((item) => item.value === valueState), | ||
[items, valueState] | ||
) | ||
|
||
return ( | ||
<BaseSelect | ||
placeholder={placeholder} | ||
text={selectedItem?.label} | ||
ref={selectRef} | ||
dropdownStyle={{ width: '100%', padding: 8 }} | ||
> | ||
{items.map((item) => ( | ||
<ListItem | ||
key={item.value} | ||
leftContent={item.leftContent} | ||
content={item.label} | ||
onClick={() => handleClickItem(item)} | ||
/> | ||
))} | ||
</BaseSelect> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { PropsWithChildren } from 'react' | ||
import { Box } from '@channel.io/bezier-react' | ||
import type { Tables } from '@/supabase/types' | ||
import { BaseLayout } from '@/layouts/BaseLayout/BaseLayout' | ||
import { SiteLayout } from '@/layouts/SiteLayout/SiteLayout' | ||
|
||
interface CustomPageLayoutProps { | ||
title: string | ||
description: string | null | ||
layout: Tables<'CustomPage'>['layout'] | ||
} | ||
|
||
export function CustomPageLayout({ | ||
title, | ||
description, | ||
layout, | ||
children, | ||
}: PropsWithChildren<CustomPageLayoutProps>) { | ||
switch (layout) { | ||
case 'SITE': { | ||
return ( | ||
<SiteLayout | ||
title={title} | ||
description={description ?? undefined} | ||
> | ||
{children} | ||
</SiteLayout> | ||
) | ||
} | ||
|
||
case 'WIDE': { | ||
return ( | ||
<BaseLayout | ||
title={title} | ||
description={description ?? undefined} | ||
> | ||
<Box | ||
as="main" | ||
padding={24} | ||
> | ||
{children} | ||
</Box> | ||
</BaseLayout> | ||
) | ||
} | ||
|
||
case 'BASE': { | ||
return ( | ||
<BaseLayout | ||
title={title} | ||
description={description ?? undefined} | ||
> | ||
<Box | ||
as="main" | ||
padding={24} | ||
maxWidth="72rem" | ||
marginHorizontal="auto" | ||
> | ||
{children} | ||
</Box> | ||
</BaseLayout> | ||
) | ||
} | ||
|
||
case 'EMPTY': | ||
default: { | ||
return ( | ||
<BaseLayout | ||
title={title} | ||
description={description ?? undefined} | ||
> | ||
{children} | ||
</BaseLayout> | ||
) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/features/custom-pages/queries/useUpdatePageMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useMutation } from '@tanstack/react-query' | ||
import { merge } from 'immutable' | ||
import { useToast } from '@channel.io/bezier-react' | ||
import axios from 'axios' | ||
import assert from 'assert' | ||
import { supabase } from '@/supabase/client' | ||
import type { Tables } from '@/supabase/types' | ||
|
||
interface UpdatePagePayload { | ||
pageId: Tables<'CustomPage'>['id'] | ||
page: Partial<Omit<Tables<'CustomPage'>, 'id' | 'created_at' | 'updated_at'>> | ||
} | ||
export function useUpdatePageMutation() { | ||
const { addToast } = useToast() | ||
|
||
return useMutation({ | ||
mutationFn: async ({ page, pageId }: UpdatePagePayload) => | ||
supabase | ||
.from('CustomPage') | ||
.update(merge(page, { updated_at: new Date() })) | ||
.eq('id', pageId) | ||
.select('id') | ||
.single() | ||
.throwOnError(), | ||
onSuccess: async (_, { pageId }) => { | ||
const { | ||
data: { session }, | ||
} = await supabase.auth.getSession() | ||
assert(session?.access_token, 'session.access_token is undefined') | ||
await axios.patch<'ok'>('/api/page/invalidate', undefined, { | ||
params: { | ||
pageId, | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${session.access_token}`, | ||
}, | ||
}) | ||
addToast('성공적으로 수정되었습니다.', { preset: 'success' }) | ||
}, | ||
onError: async () => { | ||
addToast('수정에 실패했습니다.', { preset: 'error' }) | ||
}, | ||
}) | ||
} |
2 changes: 1 addition & 1 deletion
2
...component/PostListError/PostListError.tsx → src/features/errors/ListError/ListError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ListError as PostListError } from './ListError' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
import type { PropsWithChildren } from 'react' | ||
import { useGetUserQueryObject } from '@/features/User/queries/useGetUserQueryObject' | ||
import { Redirect } from '@/components/Redirect/Redirect' | ||
|
||
export function AdminGuard() { | ||
export function AdminGuard({ children }: PropsWithChildren) { | ||
const { data } = useSuspenseQuery(useGetUserQueryObject()) | ||
|
||
if (!data || data.email !== '[email protected]') { | ||
return <Redirect to="/nabi/login" /> | ||
} | ||
|
||
return null | ||
return <>{children}</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.