) => {
const file = e.target.files?.[0];
- if (file) {
- // ํ์ผ ํฌ๊ธฐ ์ฒดํฌ (10MB)
- if (file.size > 10 * 1024 * 1024) {
- alert('ํ์ผ ํฌ๊ธฐ๋ 10MB ์ดํ์ฌ์ผ ํฉ๋๋ค.');
- return;
- }
+ if (!file) return;
- // ํ์ผ ํ์
์ฒดํฌ
- const validTypes = ['image/png', 'image/jpeg', 'image/gif'];
- if (!validTypes.includes(file.type)) {
- alert('PNG, JPEG, GIF ํ์ผ๋ง ์
๋ก๋ ๊ฐ๋ฅํฉ๋๋ค.');
- return;
- }
+ // ํ์ผ ํฌ๊ธฐ ์ฒดํฌ (10MB)
+ if (file.size > 10 * 1024 * 1024) {
+ toast.error('ํ์ผ ํฌ๊ธฐ๋ 10MB ์ดํ์ฌ์ผ ํฉ๋๋ค.');
+ return;
+ }
- // ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์ฑ
- const reader = new FileReader();
- reader.onload = (event) => {
- setProfileImage(event.target?.result as string);
- };
- reader.readAsDataURL(file);
+ // ํ์ผ ํ์
์ฒดํฌ
+ const validTypes = ['image/png', 'image/jpeg', 'image/gif'];
+ if (!validTypes.includes(file.type)) {
+ toast.error('PNG, JPEG, GIF ํ์ผ๋ง ์
๋ก๋ ๊ฐ๋ฅํฉ๋๋ค.');
+ return;
+ }
+
+ // ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์ฑ (๋๊ด์ ์
๋ฐ์ดํธ)
+ const previousImage = profileImage;
+ const reader = new FileReader();
+ reader.onload = (event) => {
+ setProfileImage(event.target?.result as string);
+ };
+ reader.readAsDataURL(file);
+
+ // API ํธ์ถ
+ setIsUploadingImage(true);
+ try {
+ const formData = new FormData();
+ formData.append('file', file);
+
+ const result = await uploadProfileImage(formData);
+ if (result.success) {
+ toast.success('ํ๋กํ ์ด๋ฏธ์ง๊ฐ ์
๋ก๋๋์์ต๋๋ค.');
+ } else {
+ // ์คํจ ์ ๋กค๋ฐฑ
+ setProfileImage(previousImage);
+ toast.error(result.error || '์ด๋ฏธ์ง ์
๋ก๋์ ์คํจํ์ต๋๋ค.');
+ }
+ } catch {
+ // ์๋ฌ ์ ๋กค๋ฐฑ
+ setProfileImage(previousImage);
+ toast.error('์๋ฒ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.');
+ } finally {
+ setIsUploadingImage(false);
+ if (fileInputRef.current) {
+ fileInputRef.current.value = '';
+ }
}
};
@@ -131,12 +142,18 @@ export function AccountInfoClient() {
};
const handleConfirmWithdraw = async () => {
+ if (!withdrawPassword) {
+ toast.error('๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.');
+ return;
+ }
+
setIsWithdrawing(true);
try {
- const result = await withdrawAccount();
+ const result = await withdrawAccount(withdrawPassword);
if (result.success) {
toast.success('๊ณ์ ์ด ํํด๋์์ต๋๋ค.');
setShowWithdrawDialog(false);
+ setWithdrawPassword('');
// ๋ก๊ทธ์์ ๋ฐ ๋ก๊ทธ์ธ ํ์ด์ง๋ก ์ด๋
router.push('/ko/login');
} else {
@@ -175,7 +192,7 @@ export function AccountInfoClient() {
router.push('/ko/settings/account-info?mode=edit');
};
- const handleMarketingChange = (type: 'email' | 'sms', checked: boolean) => {
+ const handleMarketingChange = async (type: 'email' | 'sms', checked: boolean) => {
const now = new Date().toLocaleString('ko-KR', {
year: 'numeric',
month: '2-digit',
@@ -184,6 +201,7 @@ export function AccountInfoClient() {
minute: '2-digit',
}).replace(/\. /g, '-').replace('.', '');
+ // ๋๊ด์ ์
๋ฐ์ดํธ (UI ๋จผ์ ๋ณ๊ฒฝ)
setMarketingConsent(prev => ({
...prev,
[type]: {
@@ -191,6 +209,37 @@ export function AccountInfoClient() {
...(checked ? { agreedAt: now } : { withdrawnAt: now }),
},
}));
+
+ // API ํธ์ถ
+ setIsSavingMarketing(true);
+ try {
+ const result = await updateAgreements([{ type, agreed: checked }]);
+ if (result.success) {
+ toast.success(checked ? '์์ ๋์๋์์ต๋๋ค.' : '์์ ๋์๊ฐ ์ฒ ํ๋์์ต๋๋ค.');
+ } else {
+ // ์คํจ ์ ๋กค๋ฐฑ
+ setMarketingConsent(prev => ({
+ ...prev,
+ [type]: {
+ agreed: !checked,
+ ...(checked ? { withdrawnAt: now } : { agreedAt: now }),
+ },
+ }));
+ toast.error(result.error || '๋ณ๊ฒฝ์ ์คํจํ์ต๋๋ค.');
+ }
+ } catch {
+ // ์๋ฌ ์ ๋กค๋ฐฑ
+ setMarketingConsent(prev => ({
+ ...prev,
+ [type]: {
+ agreed: !checked,
+ ...(checked ? { withdrawnAt: now } : { agreedAt: now }),
+ },
+ }));
+ toast.error('์๋ฒ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.');
+ } finally {
+ setIsSavingMarketing(false);
+ }
};
// ===== ํค๋ ์ก์
๋ฒํผ =====
@@ -269,14 +318,16 @@ export function AccountInfoClient() {
accept="image/png,image/jpeg,image/gif"
onChange={handleImageUpload}
className="hidden"
+ disabled={isUploadingImage}
/>
1250 X 250px, 10MB ์ดํ์ PNG, JPEG, GIF
@@ -371,6 +422,7 @@ export function AccountInfoClient() {
id="email-consent"
checked={marketingConsent.email.agreed}
onCheckedChange={(checked) => handleMarketingChange('email', checked as boolean)}
+ disabled={isSavingMarketing}
/>