Phase 3 - Portfolio Screens (6 files):
- [id]/index.tsx: ViewWrapper → OS_Wrapper (detail dengan pull-to-refresh)
- [id]/edit.tsx: NewWrapper → OS_Wrapper (form + keyboard handling)
- [id]/edit-logo.tsx: ViewWrapper → OS_Wrapper (upload logo)
- [id]/edit-social-media.tsx: ViewWrapper → OS_Wrapper (form + keyboard handling)
- ViewListPortofolio.tsx: NewWrapper → OS_Wrapper (pagination list)
- ScreenPortofolioCreate.tsx: NewWrapper → OS_Wrapper (form + keyboard handling)
Phase 4 - Maps Screens (2 files):
- ScreenMapsCreate.tsx: NewWrapper → OS_Wrapper (form + keyboard handling)
- ScreenMapsEdit.tsx: ViewWrapper → OS_Wrapper (form + keyboard handling)
Bug Fixes:
- Perbaiki auto-scroll keyboard yang membuat input paling atas 'terlempar' keluar layar
- Gunakan UIManager.measure untuk mendapatkan posisi absolut input (pageY) secara akurat
- Logika conditional scroll:
* Jika input terlihat (di atas keyboard) → TIDAK SCROLL
* Jika input tertutup keyboard → Scroll secukupnya
- Helper cloneChildrenWithFocusHandler sekarang aktif menyuntikan onFocus handler ke semua TextInput/TextArea/PhoneInput/Select
- Hapus KeyboardAvoidingView dari AndroidWrapper static mode (tidak diperlukan lagi)
Pattern yang diterapkan:
- List screens: contentPaddingBottom=100 (default)
- Form screens: contentPaddingBottom={250} + enableKeyboardHandling
- NO PADDING_INLINE (sesuai preferensi user - mencegah box menyempit)
Dokumentasi:
- Update TASK-005 dengan status lengkap Phase 1-4 (27 files migrated)
- Tambahkan urutan phase baru: Event (Phase 5), Voting (Phase 6), Forum (Phase 7), Donation (Phase 8)
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
153 lines
3.7 KiB
TypeScript
153 lines
3.7 KiB
TypeScript
import {
|
|
BaseBox,
|
|
BoxButtonOnFooter,
|
|
ButtonCenteredOnly,
|
|
ButtonCustom,
|
|
OS_Wrapper
|
|
} from "@/components";
|
|
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
|
import DIRECTORY_ID from "@/constants/directory-id";
|
|
import DUMMY_IMAGE from "@/constants/dummy-image-value";
|
|
import { useAuth } from "@/hooks/use-auth";
|
|
import { apiFileDelete } from "@/service/api-client/api-file";
|
|
import {
|
|
apiGetOnePortofolio,
|
|
apiUpdatePortofolio,
|
|
} from "@/service/api-client/api-portofolio";
|
|
import { uploadFileService } from "@/service/upload-service";
|
|
import pickImage from "@/utils/pickImage";
|
|
import { Image } from "expo-image";
|
|
import { router, useLocalSearchParams } from "expo-router";
|
|
import { useEffect, useState } from "react";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
export default function PortofolioEditLogo() {
|
|
const { id } = useLocalSearchParams();
|
|
const [logoId, setLogoId] = useState<any>();
|
|
const [imageUri, setImageUri] = useState<string | null>(null);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const { token } = useAuth();
|
|
|
|
useEffect(() => {
|
|
onLoadData(id as string);
|
|
}, [id]);
|
|
|
|
const onLoadData = async (id: string) => {
|
|
const response = await apiGetOnePortofolio({ id: id });
|
|
console.log(
|
|
"Response portofolio >>",
|
|
JSON.stringify(response.data.logoId, null, 2)
|
|
);
|
|
setLogoId(response.data.logoId);
|
|
};
|
|
|
|
async function onUpload() {
|
|
try {
|
|
setIsLoading(true);
|
|
|
|
const response = await uploadFileService({
|
|
imageUri,
|
|
dirId: DIRECTORY_ID.portofolio_logo,
|
|
});
|
|
|
|
if (response.success) {
|
|
const fileId = response.data.id;
|
|
const responseUpdate = await apiUpdatePortofolio({
|
|
id: id as string,
|
|
data: { fileId },
|
|
category: "logo",
|
|
});
|
|
|
|
if (!responseUpdate.success) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Info",
|
|
text2: responseUpdate.message,
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (logoId) {
|
|
const deletePrevFile = await apiFileDelete({
|
|
token: token as string,
|
|
id: logoId as string,
|
|
});
|
|
|
|
if (!deletePrevFile.success) {
|
|
console.log("error delete prev file >>", deletePrevFile.message);
|
|
}
|
|
}
|
|
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Sukses",
|
|
text2: "Logo berhasil diupdate",
|
|
});
|
|
|
|
router.back();
|
|
}
|
|
} catch (error) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Gagal",
|
|
text2: error as string,
|
|
});
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}
|
|
|
|
const image = imageUri ? (
|
|
<Image source={{ uri: imageUri }} style={{ width: 200, height: 200 }} />
|
|
) : (
|
|
<Image
|
|
source={
|
|
logoId
|
|
? { uri: API_STRORAGE.GET({ fileId: logoId }) }
|
|
: DUMMY_IMAGE.avatar
|
|
}
|
|
style={{ width: 200, height: 200 }}
|
|
/>
|
|
);
|
|
|
|
const buttonFooter = (
|
|
<BoxButtonOnFooter>
|
|
<ButtonCustom
|
|
isLoading={isLoading}
|
|
disabled={isLoading}
|
|
onPress={() => {
|
|
onUpload();
|
|
}}
|
|
>
|
|
Update
|
|
</ButtonCustom>
|
|
</BoxButtonOnFooter>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<OS_Wrapper footerComponent={buttonFooter}>
|
|
<BaseBox
|
|
style={{
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
height: 250,
|
|
}}
|
|
>
|
|
{image}
|
|
</BaseBox>
|
|
<ButtonCenteredOnly
|
|
icon="upload"
|
|
onPress={() => {
|
|
pickImage({
|
|
setImageUri,
|
|
});
|
|
}}
|
|
>
|
|
Upload
|
|
</ButtonCenteredOnly>
|
|
</OS_Wrapper>
|
|
</>
|
|
);
|
|
}
|