[feat] solution: SNS 연동 확인용 테스트 게시 기능 추가
This commit is contained in:
1 parent
d77f2aa14c
commit
921c85df25
4 files changed
+114
No files matched your search
@@ -23,6 +23,11 @@ export function SocialConnectionCard() {
|
||||
const [state, setState] = useState<SocialState | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [testText, setTestText] = useState('');
|
||||
const [testBusy, setTestBusy] = useState(false);
|
||||
const [testError, setTestError] = useState('');
|
||||
const [testPosted, setTestPosted] = useState(false);
|
||||
const [testPermalink, setTestPermalink] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
@@ -64,6 +69,25 @@ export function SocialConnectionCard() {
|
||||
window.location.assign(url);
|
||||
});
|
||||
|
||||
async function testPost() {
|
||||
setTestBusy(true);
|
||||
setTestError('');
|
||||
setTestPosted(false);
|
||||
setTestPermalink(null);
|
||||
try {
|
||||
const result = await socialApi<{id: string; permalink: string | null}>('/test-post', {
|
||||
text: testText,
|
||||
});
|
||||
setTestPosted(true);
|
||||
setTestPermalink(result.permalink);
|
||||
setTestText('');
|
||||
} catch (e) {
|
||||
setTestError(e instanceof Error ? e.message : '요청을 처리하지 못했습니다.');
|
||||
} finally {
|
||||
setTestBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="mb-4 rounded-xl border border-border p-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
@@ -116,6 +140,58 @@ export function SocialConnectionCard() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{account && !needsReauth && (
|
||||
<div className="mt-3 border-t border-border pt-3">
|
||||
<label htmlFor="social-test-text" className="text-xs font-bold">
|
||||
연동 확인용 테스트 게시
|
||||
</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input
|
||||
id="social-test-text"
|
||||
type="text"
|
||||
value={testText}
|
||||
onChange={(e) => setTestText(e.target.value)}
|
||||
placeholder="이 계정으로 바로 올라갑니다"
|
||||
maxLength={500}
|
||||
className="min-w-0 flex-1 rounded-md border border-border px-2 py-1 text-xs"
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={testBusy || !testText.trim()}
|
||||
onClick={testPost}
|
||||
>
|
||||
{testBusy ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||
<span>테스트 게시</span>
|
||||
</Button>
|
||||
</div>
|
||||
{testPosted && (
|
||||
<p className="mt-1 text-xs">
|
||||
{testPermalink ? (
|
||||
<>
|
||||
게시됐습니다:{' '}
|
||||
<a
|
||||
href={testPermalink}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="font-bold underline underline-offset-4"
|
||||
>
|
||||
확인하기 →
|
||||
</a>
|
||||
</>
|
||||
) : (
|
||||
'게시됐습니다. 잠시 후 계정에서 직접 확인해 주세요.'
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{testError && (
|
||||
<p role="alert" className="mt-1 text-xs text-destructive">
|
||||
{testError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 게재가 아직 안 열린 상태를 숨기지 않는다 — 연결만 해 두고 기다리는 것도 사장님의 선택이다. */}
|
||||
{ready && !state.posting_enabled && (
|
||||
<p className="mt-3 text-xs text-muted-foreground">
|
||||
|
||||
@@ -19,6 +19,8 @@ const messages: Record<string, string> = {
|
||||
PUBLISH_URL_CHANGED: '홈페이지 주소가 변경되었습니다. 기존 승인으로 게재할 수 없습니다.',
|
||||
APPROVAL_NOT_FOUND: '유효하지 않거나 교체된 승인 링크입니다.',
|
||||
PLACE_NOT_FOUND: '가게를 찾을 수 없습니다.',
|
||||
ACCOUNT_NEEDS_REAUTH: '연결이 만료됐습니다. 다시 연결해 주세요.',
|
||||
TEXT_TOO_LONG: '글이 너무 깁니다.',
|
||||
};
|
||||
export async function socialApi<T>(path: string, data?: unknown, publicAccess = false): Promise<T> {
|
||||
const token = publicAccess ? null : getAccessToken();
|
||||
|
||||
Reference in new issue
Block a user