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>
191 lines
4.6 KiB
TypeScript
191 lines
4.6 KiB
TypeScript
import {
|
|
BoxButtonOnFooter,
|
|
ButtonCustom,
|
|
InformationBox,
|
|
BaseBox,
|
|
Spacing,
|
|
TextInputCustom,
|
|
LandscapeFrameUploaded,
|
|
ButtonCenteredOnly,
|
|
OS_Wrapper,
|
|
} from "@/components";
|
|
import { MapSelectedPlatform } from "@/components/Map/MapSelectedPlatform";
|
|
import DIRECTORY_ID from "@/constants/directory-id";
|
|
import { useAuth } from "@/hooks/use-auth";
|
|
import { apiMapsCreate } from "@/service/api-client/api-maps";
|
|
import { uploadFileService } from "@/service/upload-service";
|
|
import { IFileData } from "@/utils/pickFile";
|
|
import pickFile from "@/utils/pickFile";
|
|
import { router, useLocalSearchParams } from "expo-router";
|
|
import { useState } from "react";
|
|
import { LatLng } from "react-native-maps";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
/**
|
|
* Screen untuk create maps
|
|
*
|
|
* Fitur:
|
|
* - Pilih lokasi dari map
|
|
* - Input nama pin
|
|
* - Upload foto lokasi
|
|
* - Submit data maps
|
|
*/
|
|
export function Maps_ScreenMapsCreate() {
|
|
const { user } = useAuth();
|
|
const { id } = useLocalSearchParams();
|
|
|
|
// State management
|
|
// Format: LatLng { latitude, longitude } untuk konsistensi
|
|
const [selectedLocation, setSelectedLocation] = useState<LatLng | null>(null);
|
|
const [name, setName] = useState<string>("");
|
|
const [image, setImage] = useState<IFileData | null>(null);
|
|
const [isLoading, setLoading] = useState(false);
|
|
|
|
/**
|
|
* Handle submit form
|
|
* Upload image (jika ada) dan submit data maps ke API
|
|
*/
|
|
const handleSubmit = async () => {
|
|
try {
|
|
setLoading(true);
|
|
|
|
// Prepare data tanpa image dulu
|
|
let newData: any = {
|
|
authorId: user?.id,
|
|
portofolioId: id,
|
|
namePin: name,
|
|
latitude: selectedLocation?.latitude,
|
|
longitude: selectedLocation?.longitude,
|
|
};
|
|
|
|
// Upload image jika ada
|
|
if (image) {
|
|
const responseUpload = await uploadFileService({
|
|
dirId: DIRECTORY_ID.map_image,
|
|
imageUri: image?.uri,
|
|
});
|
|
|
|
if (!responseUpload?.data?.id) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Gagal mengunggah gambar",
|
|
});
|
|
return;
|
|
}
|
|
|
|
const imageId = responseUpload?.data?.id;
|
|
|
|
newData = {
|
|
authorId: user?.id,
|
|
portofolioId: id,
|
|
namePin: name,
|
|
latitude: selectedLocation?.latitude,
|
|
longitude: selectedLocation?.longitude,
|
|
imageId: imageId,
|
|
};
|
|
}
|
|
|
|
// Submit ke API
|
|
const response = await apiMapsCreate({
|
|
data: newData,
|
|
});
|
|
|
|
if (!response.success) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Gagal menambahkan map",
|
|
});
|
|
return;
|
|
}
|
|
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Map berhasil ditambahkan",
|
|
});
|
|
router.back();
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle image upload
|
|
*/
|
|
const handleImageUpload = async () => {
|
|
try {
|
|
await pickFile({
|
|
allowedType: "image",
|
|
setImageUri: (file) => {
|
|
setImage(file);
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.log("[MapsCreate] Image upload error:", error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Footer component dengan button submit
|
|
*/
|
|
const buttonFooter = (
|
|
<BoxButtonOnFooter>
|
|
<ButtonCustom
|
|
isLoading={isLoading}
|
|
disabled={!selectedLocation || name === ""}
|
|
onPress={handleSubmit}
|
|
>
|
|
Simpan
|
|
</ButtonCustom>
|
|
</BoxButtonOnFooter>
|
|
);
|
|
|
|
/**
|
|
* Render screen dengan OS_Wrapper
|
|
*/
|
|
return (
|
|
<OS_Wrapper
|
|
enableKeyboardHandling
|
|
contentPaddingBottom={250}
|
|
footerComponent={buttonFooter}
|
|
>
|
|
<InformationBox text="Tentukan lokasi pin map dengan menekan pada map." />
|
|
|
|
<BaseBox>
|
|
<MapSelectedPlatform
|
|
selectedLocation={selectedLocation}
|
|
onLocationSelect={(location) => {
|
|
setSelectedLocation(location as LatLng);
|
|
}}
|
|
height={300}
|
|
showUserLocation={true}
|
|
showsMyLocationButton={true}
|
|
/>
|
|
</BaseBox>
|
|
|
|
<TextInputCustom
|
|
required
|
|
label="Nama Pin"
|
|
placeholder="Masukkan nama pin maps"
|
|
value={name}
|
|
onChangeText={setName}
|
|
/>
|
|
|
|
<Spacing height={50} />
|
|
|
|
<InformationBox text="Upload foto lokasi bisnis anda untuk ditampilkan dalam detail maps." />
|
|
|
|
<LandscapeFrameUploaded image={image?.uri} />
|
|
|
|
<ButtonCenteredOnly icon="upload" onPress={handleImageUpload}>
|
|
Upload
|
|
</ButtonCenteredOnly>
|
|
|
|
<Spacing height={50} />
|
|
</OS_Wrapper>
|
|
);
|
|
}
|
|
|
|
export default Maps_ScreenMapsCreate;
|