diff --git a/app/(application)/(user)/profile/[id]/edit.tsx b/app/(application)/(user)/profile/[id]/edit.tsx index 1cfee8d..9526117 100644 --- a/app/(application)/(user)/profile/[id]/edit.tsx +++ b/app/(application)/(user)/profile/[id]/edit.tsx @@ -54,6 +54,8 @@ export default function ProfileEdit() { return; } + + Toast.show({ type: "success", text1: "Sukses", diff --git a/app/(application)/(user)/profile/[id]/update-photo.tsx b/app/(application)/(user)/profile/[id]/update-photo.tsx index 1aa2a41..e9eb0d6 100644 --- a/app/(application)/(user)/profile/[id]/update-photo.tsx +++ b/app/(application)/(user)/profile/[id]/update-photo.tsx @@ -50,6 +50,11 @@ export default function UpdatePhotoProfile() { dirId: DIRECTORY_ID.profile_foto, }); + console.log( + "response upload photo>>", + JSON.stringify(response, null, 2) + ); + if (response.success) { const fileId = response.data.id; await apiUpdateProfile({ diff --git a/app/(application)/(user)/profile/create.tsx b/app/(application)/(user)/profile/create.tsx index b23af22..537e9ac 100644 --- a/app/(application)/(user)/profile/create.tsx +++ b/app/(application)/(user)/profile/create.tsx @@ -1,25 +1,34 @@ import { - AvatarCustom, + BaseBox, ButtonCenteredOnly, ButtonCustom, SelectCustom, Spacing, StackCustom, TextInputCustom, - ViewWrapper, + ViewWrapper } from "@/components"; import BoxButtonOnFooter from "@/components/Box/BoxButtonOnFooter"; import InformationBox from "@/components/Box/InformationBox"; -import LandscapeFrameUploaded from "@/components/Image/LandscapeFrameUploaded"; +import DIRECTORY_ID from "@/constants/directory-id"; +import DUMMY_IMAGE from "@/constants/dummy-image-value"; import { useAuth } from "@/hooks/use-auth"; -import { apiCreateProfile } from "@/service/api-client/api-profile"; -import { router, useFocusEffect } from "expo-router"; -import { useCallback, useState } from "react"; -import { View } from "react-native"; +import { + apiCreateProfile +} from "@/service/api-client/api-profile"; +import { apiValidationEmail } from "@/service/api-client/api-validation"; +import { uploadImageService } from "@/service/upload-service"; +import pickImage from "@/utils/pickImage"; +import { router } from "expo-router"; +import { useEffect, useState } from "react"; +import { Image, View } from "react-native"; +import { Avatar } from "react-native-paper"; import Toast from "react-native-toast-message"; export default function CreateProfile() { const { user } = useAuth(); + const [imagePhoto, setImagePhoto] = useState(null); + const [imageBackground, setImageBackground] = useState(null); const [isLoading, setIsLoading] = useState(false); const [data, setData] = useState({ @@ -30,17 +39,19 @@ export default function CreateProfile() { jenisKelamin: "", }); - useFocusEffect( - useCallback(() => { - Toast.show({ - type: "info", - text1: "Lengkapi Profile Anda", - text2: "Untuk menjelajahi fitur-fitur yang ada", - }); - }, []) - ); + useEffect(() => { + Toast.show({ + type: "info", + text1: "Lengkapi Profile Anda", + text2: "Untuk menjelajahi fitur-fitur yang ada", + }); + }, []); const handlerSave = async () => { + let IMG = { + imageId: "", + imageBackgroundId: "", + }; if (!data.name || !data.email || !data.alamat || !data.jenisKelamin) { Toast.show({ type: "info", @@ -52,7 +63,72 @@ export default function CreateProfile() { try { setIsLoading(true); - const response = await apiCreateProfile(data); + + const responseValidateEmail = await apiValidationEmail({ + email: data.email, + }); + + if (!responseValidateEmail.success) { + Toast.show({ + type: "error", + text1: "Gagal", + text2: responseValidateEmail.message, + }); + return; + } + + console.log( + "responseValidateEmail >>", + JSON.stringify(responseValidateEmail, null, 2) + ); + + + + + + + if (imagePhoto) { + const responseUploadPhoto = await uploadImageService({ + imageUri: imagePhoto, + dirId: DIRECTORY_ID.profile_foto, + }); + + console.log( + "responseUploadPhoto >>", + JSON.stringify(responseUploadPhoto, null, 2) + ); + + if (responseUploadPhoto.success) { + const fileIdPhoto = responseUploadPhoto.data.id; + + IMG.imageId = fileIdPhoto; + } + } + + if (imageBackground) { + const responseUploadBackground = await uploadImageService({ + imageUri: imageBackground, + dirId: DIRECTORY_ID.profile_background, + }); + + console.log( + "responseUploadBackground >>", + JSON.stringify(responseUploadBackground, null, 2) + ); + + if (responseUploadBackground.success) { + const fileIdBackground = responseUploadBackground.data.id; + + IMG.imageBackgroundId = fileIdBackground; + } + } + + const fixData = { + ...data, + ...IMG, + }; + + const response = await apiCreateProfile(fixData); if (response.status === 400) { Toast.show({ type: "error", @@ -67,7 +143,10 @@ export default function CreateProfile() { text1: "Sukses", text2: "Profile berhasil dibuat", }); + + console.log("fixResponse >>", JSON.stringify(response, null, 2)); router.push("/(application)/(user)/home"); + return; } catch (error) { console.log("error create profile >>", error); } finally { @@ -92,11 +171,18 @@ export default function CreateProfile() { - + router.navigate(`/take-picture/${user?.id}`)} + onPress={() => { + pickImage({ + setImageUri: setImagePhoto, + }); + }} > Upload @@ -106,11 +192,24 @@ export default function CreateProfile() { - - + + + + {/* */} router.navigate(`/take-picture/${user?.id}`)} + onPress={() => { + pickImage({ + setImageUri: setImageBackground, + }); + }} > Upload diff --git a/service/api-client/api-validation.ts b/service/api-client/api-validation.ts new file mode 100644 index 0000000..d98d31b --- /dev/null +++ b/service/api-client/api-validation.ts @@ -0,0 +1,8 @@ +import { apiConfig } from "../api-config"; + +export async function apiValidationEmail({ email }: { email: string }) { + const response = await apiConfig.post(`/mobile/validate/email`, { + data: email, + }); + return response.data; +} diff --git a/service/upload-service.ts b/service/upload-service.ts index 2fa37f2..1210cc4 100644 --- a/service/upload-service.ts +++ b/service/upload-service.ts @@ -47,10 +47,11 @@ export async function uploadImageService({ "Content-Type": "multipart/form-data", Authorization: `Bearer ${token}`, }, - timeout: 30000, + // timeout: 30000, }); const { data } = response; + console.log("response upload >>", JSON.stringify(data, null, 2)); if (!data.success) { Toast.show({ @@ -62,10 +63,10 @@ export async function uploadImageService({ return; } - Toast.show({ - type: "success", - text1: "File berhasil diunggah", - }); + // Toast.show({ + // type: "success", + // text1: "File berhasil diunggah", + // }); return data; } catch (error) {