Profile
Add: - Api upload background - /api-client/api-validation.ts ### No Issue
This commit is contained in:
@@ -54,6 +54,8 @@ export default function ProfileEdit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Toast.show({
|
Toast.show({
|
||||||
type: "success",
|
type: "success",
|
||||||
text1: "Sukses",
|
text1: "Sukses",
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ export default function UpdatePhotoProfile() {
|
|||||||
dirId: DIRECTORY_ID.profile_foto,
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"response upload photo>>",
|
||||||
|
JSON.stringify(response, null, 2)
|
||||||
|
);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
const fileId = response.data.id;
|
const fileId = response.data.id;
|
||||||
await apiUpdateProfile({
|
await apiUpdateProfile({
|
||||||
|
|||||||
@@ -1,25 +1,34 @@
|
|||||||
import {
|
import {
|
||||||
AvatarCustom,
|
BaseBox,
|
||||||
ButtonCenteredOnly,
|
ButtonCenteredOnly,
|
||||||
ButtonCustom,
|
ButtonCustom,
|
||||||
SelectCustom,
|
SelectCustom,
|
||||||
Spacing,
|
Spacing,
|
||||||
StackCustom,
|
StackCustom,
|
||||||
TextInputCustom,
|
TextInputCustom,
|
||||||
ViewWrapper,
|
ViewWrapper
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import BoxButtonOnFooter from "@/components/Box/BoxButtonOnFooter";
|
import BoxButtonOnFooter from "@/components/Box/BoxButtonOnFooter";
|
||||||
import InformationBox from "@/components/Box/InformationBox";
|
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 { useAuth } from "@/hooks/use-auth";
|
||||||
import { apiCreateProfile } from "@/service/api-client/api-profile";
|
import {
|
||||||
import { router, useFocusEffect } from "expo-router";
|
apiCreateProfile
|
||||||
import { useCallback, useState } from "react";
|
} from "@/service/api-client/api-profile";
|
||||||
import { View } from "react-native";
|
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";
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function CreateProfile() {
|
export default function CreateProfile() {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
const [imagePhoto, setImagePhoto] = useState<string | null>(null);
|
||||||
|
const [imageBackground, setImageBackground] = useState<string | null>(null);
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [data, setData] = useState({
|
const [data, setData] = useState({
|
||||||
@@ -30,17 +39,19 @@ export default function CreateProfile() {
|
|||||||
jenisKelamin: "",
|
jenisKelamin: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
useFocusEffect(
|
useEffect(() => {
|
||||||
useCallback(() => {
|
Toast.show({
|
||||||
Toast.show({
|
type: "info",
|
||||||
type: "info",
|
text1: "Lengkapi Profile Anda",
|
||||||
text1: "Lengkapi Profile Anda",
|
text2: "Untuk menjelajahi fitur-fitur yang ada",
|
||||||
text2: "Untuk menjelajahi fitur-fitur yang ada",
|
});
|
||||||
});
|
}, []);
|
||||||
}, [])
|
|
||||||
);
|
|
||||||
|
|
||||||
const handlerSave = async () => {
|
const handlerSave = async () => {
|
||||||
|
let IMG = {
|
||||||
|
imageId: "",
|
||||||
|
imageBackgroundId: "",
|
||||||
|
};
|
||||||
if (!data.name || !data.email || !data.alamat || !data.jenisKelamin) {
|
if (!data.name || !data.email || !data.alamat || !data.jenisKelamin) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
type: "info",
|
type: "info",
|
||||||
@@ -52,7 +63,72 @@ export default function CreateProfile() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
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) {
|
if (response.status === 400) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
type: "error",
|
type: "error",
|
||||||
@@ -67,7 +143,10 @@ export default function CreateProfile() {
|
|||||||
text1: "Sukses",
|
text1: "Sukses",
|
||||||
text2: "Profile berhasil dibuat",
|
text2: "Profile berhasil dibuat",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("fixResponse >>", JSON.stringify(response, null, 2));
|
||||||
router.push("/(application)/(user)/home");
|
router.push("/(application)/(user)/home");
|
||||||
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error create profile >>", error);
|
console.log("error create profile >>", error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -92,11 +171,18 @@ export default function CreateProfile() {
|
|||||||
<StackCustom>
|
<StackCustom>
|
||||||
<InformationBox text="Upload foto profile anda." />
|
<InformationBox text="Upload foto profile anda." />
|
||||||
<View style={{ alignItems: "center" }}>
|
<View style={{ alignItems: "center" }}>
|
||||||
<AvatarCustom size="xl" />
|
<Avatar.Image
|
||||||
|
size={100}
|
||||||
|
source={imagePhoto ? { uri: imagePhoto } : DUMMY_IMAGE.avatar}
|
||||||
|
/>
|
||||||
<Spacing />
|
<Spacing />
|
||||||
<ButtonCenteredOnly
|
<ButtonCenteredOnly
|
||||||
icon="upload"
|
icon="upload"
|
||||||
onPress={() => router.navigate(`/take-picture/${user?.id}`)}
|
onPress={() => {
|
||||||
|
pickImage({
|
||||||
|
setImageUri: setImagePhoto,
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Upload
|
Upload
|
||||||
</ButtonCenteredOnly>
|
</ButtonCenteredOnly>
|
||||||
@@ -106,11 +192,24 @@ export default function CreateProfile() {
|
|||||||
|
|
||||||
<View>
|
<View>
|
||||||
<InformationBox text="Upload foto latar belakang anda." />
|
<InformationBox text="Upload foto latar belakang anda." />
|
||||||
<LandscapeFrameUploaded />
|
<BaseBox>
|
||||||
<Spacing />
|
<Image
|
||||||
|
source={
|
||||||
|
imageBackground
|
||||||
|
? { uri: imageBackground }
|
||||||
|
: DUMMY_IMAGE.background
|
||||||
|
}
|
||||||
|
style={{ width: "100%", height: 200 }}
|
||||||
|
/>
|
||||||
|
</BaseBox>
|
||||||
|
{/* <Spacing /> */}
|
||||||
<ButtonCenteredOnly
|
<ButtonCenteredOnly
|
||||||
icon="upload"
|
icon="upload"
|
||||||
onPress={() => router.navigate(`/take-picture/${user?.id}`)}
|
onPress={() => {
|
||||||
|
pickImage({
|
||||||
|
setImageUri: setImageBackground,
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Upload
|
Upload
|
||||||
</ButtonCenteredOnly>
|
</ButtonCenteredOnly>
|
||||||
|
|||||||
8
service/api-client/api-validation.ts
Normal file
8
service/api-client/api-validation.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -47,10 +47,11 @@ export async function uploadImageService({
|
|||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
timeout: 30000,
|
// timeout: 30000,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
|
console.log("response upload >>", JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
@@ -62,10 +63,10 @@ export async function uploadImageService({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.show({
|
// Toast.show({
|
||||||
type: "success",
|
// type: "success",
|
||||||
text1: "File berhasil diunggah",
|
// text1: "File berhasil diunggah",
|
||||||
});
|
// });
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user