Compare commits
5 Commits
api/26-aug
...
api-file/2
| Author | SHA1 | Date | |
|---|---|---|---|
| 88527d5bb6 | |||
| 40441c929f | |||
| d3c4f04e07 | |||
| 4fc2c90702 | |||
| 2227aaa99f |
@@ -1,9 +1,33 @@
|
|||||||
import { LandscapeFrameUploaded, ViewWrapper } from "@/components";
|
import { CenterCustom, TextCustom, ViewWrapper } from "@/components";
|
||||||
|
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
||||||
|
import { Image } from "expo-image";
|
||||||
|
import { useLocalSearchParams } from "expo-router";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
|
||||||
export default function PreviewImage() {
|
export default function PreviewImage() {
|
||||||
|
const { id } = useLocalSearchParams();
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ViewWrapper>
|
<ViewWrapper>
|
||||||
<LandscapeFrameUploaded />
|
{id ? (
|
||||||
|
<Image
|
||||||
|
onLoad={() => {
|
||||||
|
setIsLoading(false);
|
||||||
|
}}
|
||||||
|
source={
|
||||||
|
isLoading
|
||||||
|
? require("@/assets/images/loading.gif")
|
||||||
|
: API_STRORAGE.GET({ fileId: id as string })
|
||||||
|
}
|
||||||
|
contentFit="contain"
|
||||||
|
style={{ width: "100%", height: "100%" }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<CenterCustom>
|
||||||
|
<TextCustom>File not found</TextCustom>
|
||||||
|
</CenterCustom>
|
||||||
|
)}
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
Spacing,
|
Spacing,
|
||||||
StackCustom,
|
StackCustom,
|
||||||
TextCustom,
|
TextCustom,
|
||||||
ViewWrapper
|
ViewWrapper,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import { IconEdit } from "@/components/_Icon";
|
import { IconEdit } from "@/components/_Icon";
|
||||||
import Collaboration_BoxDetailSection from "@/screens/Collaboration/BoxDetailSection";
|
import Collaboration_BoxDetailSection from "@/screens/Collaboration/BoxDetailSection";
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export default function Application() {
|
|||||||
|
|
||||||
async function onLoadData() {
|
async function onLoadData() {
|
||||||
const response = await apiUser(user?.id as string);
|
const response = await apiUser(user?.id as string);
|
||||||
|
console.log("User >>", JSON.stringify(response.data, null, 2));
|
||||||
setData(response.data);
|
setData(response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,11 @@ export default function ProfileEdit() {
|
|||||||
const handleUpdate = async () => {
|
const handleUpdate = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const response = await apiUpdateProfile({ id: id as string, data });
|
const response = await apiUpdateProfile({
|
||||||
|
id: id as string,
|
||||||
|
data,
|
||||||
|
category: "profile",
|
||||||
|
});
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
type: "info",
|
type: "info",
|
||||||
@@ -50,6 +54,8 @@ export default function ProfileEdit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Toast.show({
|
Toast.show({
|
||||||
type: "success",
|
type: "success",
|
||||||
text1: "Sukses",
|
text1: "Sukses",
|
||||||
|
|||||||
@@ -5,40 +5,132 @@ import {
|
|||||||
ButtonCustom,
|
ButtonCustom,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
||||||
|
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 DUMMY_IMAGE from "@/constants/dummy-image-value";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
import { apiProfile, apiUpdateProfile } from "@/service/api-client/api-profile";
|
||||||
|
import { uploadImageService } from "@/service/upload-service";
|
||||||
|
import { IProfile } from "@/types/Type-Profile";
|
||||||
|
import pickImage from "@/utils/pickImage";
|
||||||
|
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
import { Image } from "react-native";
|
import { Image } from "react-native";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function UpdateBackgroundProfile() {
|
export default function UpdateBackgroundProfile() {
|
||||||
const { id } = useLocalSearchParams();
|
const { id } = useLocalSearchParams();
|
||||||
|
const [data, setData] = useState<IProfile>();
|
||||||
|
const [imageUri, setImageUri] = useState<string | null>(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
onLoadData(id as string);
|
||||||
|
}, [id])
|
||||||
|
);
|
||||||
|
|
||||||
|
async function onLoadData(id: string) {
|
||||||
|
try {
|
||||||
|
const response = await apiProfile({ id });
|
||||||
|
console.log(
|
||||||
|
"response image id >>",
|
||||||
|
JSON.stringify(response.data.backgroundId, null, 2)
|
||||||
|
);
|
||||||
|
setData(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error get profile >>", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onUpload() {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
const response = await uploadImageService({
|
||||||
|
imageUri,
|
||||||
|
dirId: DIRECTORY_ID.profile_background,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
const fileId = response.data.id;
|
||||||
|
const responseUpdate = await apiUpdateProfile({
|
||||||
|
id: id as string,
|
||||||
|
data: { fileId },
|
||||||
|
category: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!responseUpdate.success) {
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Info",
|
||||||
|
text2: responseUpdate.message,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: "Sukses",
|
||||||
|
text2: "Background berhasil diupdate",
|
||||||
|
});
|
||||||
|
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Gagal",
|
||||||
|
text2: error as string,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const buttonFooter = (
|
const buttonFooter = (
|
||||||
<BoxButtonOnFooter>
|
<BoxButtonOnFooter>
|
||||||
<ButtonCustom
|
<ButtonCustom
|
||||||
|
isLoading={isLoading}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
console.log("Simpan foto background >>", id);
|
onUpload();
|
||||||
router.back();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Simpan
|
Update
|
||||||
</ButtonCustom>
|
</ButtonCustom>
|
||||||
</BoxButtonOnFooter>
|
</BoxButtonOnFooter>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const image = imageUri ? (
|
||||||
|
<Image
|
||||||
|
source={{ uri: imageUri }}
|
||||||
|
style={{ width: "100%", height: "100%" }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
source={
|
||||||
|
data?.imageBackgroundId
|
||||||
|
? { uri: API_STRORAGE.GET({ fileId: data.imageBackgroundId }) }
|
||||||
|
: DUMMY_IMAGE.background
|
||||||
|
}
|
||||||
|
style={{ width: "100%", height: "100%", borderRadius: 10 }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ViewWrapper footerComponent={buttonFooter}>
|
<ViewWrapper footerComponent={buttonFooter}>
|
||||||
<BaseBox
|
<BaseBox
|
||||||
style={{ alignItems: "center", justifyContent: "center", height: 250 }}
|
style={{ alignItems: "center", justifyContent: "center", height: 250 }}
|
||||||
>
|
>
|
||||||
<Image
|
{image}
|
||||||
source={DUMMY_IMAGE.background}
|
|
||||||
resizeMode="cover"
|
|
||||||
style={{ width: "100%", height: "100%", borderRadius: 10 }}
|
|
||||||
/>
|
|
||||||
</BaseBox>
|
</BaseBox>
|
||||||
|
|
||||||
<ButtonCenteredOnly
|
<ButtonCenteredOnly
|
||||||
icon="upload"
|
icon="upload"
|
||||||
onPress={() => router.navigate(`/(application)/take-picture/${id}`)}
|
onPress={() => {
|
||||||
|
pickImage({
|
||||||
|
setImageUri,
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Update
|
Update
|
||||||
</ButtonCenteredOnly>
|
</ButtonCenteredOnly>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
AvatarCustom,
|
|
||||||
BaseBox,
|
BaseBox,
|
||||||
BoxButtonOnFooter,
|
BoxButtonOnFooter,
|
||||||
ButtonCenteredOnly,
|
ButtonCenteredOnly,
|
||||||
@@ -9,13 +8,14 @@ import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
|||||||
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
||||||
import DIRECTORY_ID from "@/constants/directory-id";
|
import DIRECTORY_ID from "@/constants/directory-id";
|
||||||
import DUMMY_IMAGE from "@/constants/dummy-image-value";
|
import DUMMY_IMAGE from "@/constants/dummy-image-value";
|
||||||
import { apiProfile } from "@/service/api-client/api-profile";
|
import { apiProfile, apiUpdateProfile } from "@/service/api-client/api-profile";
|
||||||
import { uploadImageService } from "@/service/upload-service";
|
import { uploadImageService } from "@/service/upload-service";
|
||||||
import { IProfile } from "@/types/Type-Profile";
|
import { IProfile } from "@/types/Type-Profile";
|
||||||
import pickImage from "@/utils/pickImage";
|
import pickImage from "@/utils/pickImage";
|
||||||
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { Image } from "react-native";
|
import { Image } from "react-native";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function UpdatePhotoProfile() {
|
export default function UpdatePhotoProfile() {
|
||||||
const { id } = useLocalSearchParams();
|
const { id } = useLocalSearchParams();
|
||||||
@@ -32,10 +32,6 @@ export default function UpdatePhotoProfile() {
|
|||||||
async function onLoadData(id: string) {
|
async function onLoadData(id: string) {
|
||||||
try {
|
try {
|
||||||
const response = await apiProfile({ id });
|
const response = await apiProfile({ id });
|
||||||
console.log(
|
|
||||||
"response image id >>",
|
|
||||||
JSON.stringify(response.data.imageId, null, 2)
|
|
||||||
);
|
|
||||||
setData(response.data);
|
setData(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error get profile >>", error);
|
console.log("error get profile >>", error);
|
||||||
@@ -51,12 +47,39 @@ export default function UpdatePhotoProfile() {
|
|||||||
dirId: DIRECTORY_ID.profile_foto,
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Upload res >>", JSON.stringify(response, null, 2));
|
console.log("response upload photo>>", JSON.stringify(response, null, 2));
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
const fileId = response.data.id;
|
||||||
|
const responseUpdate = await apiUpdateProfile({
|
||||||
|
id: id as string,
|
||||||
|
data: { fileId },
|
||||||
|
category: "photo",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!responseUpdate.success) {
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Info",
|
||||||
|
text2: responseUpdate.message,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: "Sukses",
|
||||||
|
text2: "Photo berhasil diupdate",
|
||||||
|
});
|
||||||
|
|
||||||
router.back();
|
router.back();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error upload >>", error);
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Gagal",
|
||||||
|
text2: error as string,
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -68,8 +91,6 @@ export default function UpdatePhotoProfile() {
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
onUpload();
|
onUpload();
|
||||||
// console.log("Simpan foto profile >>", id);
|
|
||||||
// router.back();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Update
|
Update
|
||||||
@@ -80,13 +101,13 @@ export default function UpdatePhotoProfile() {
|
|||||||
const image = imageUri ? (
|
const image = imageUri ? (
|
||||||
<Image source={{ uri: imageUri }} style={{ width: 200, height: 200 }} />
|
<Image source={{ uri: imageUri }} style={{ width: 200, height: 200 }} />
|
||||||
) : (
|
) : (
|
||||||
<AvatarCustom
|
<Image
|
||||||
size="xl"
|
|
||||||
source={
|
source={
|
||||||
data?.imageId
|
data?.imageId
|
||||||
? API_STRORAGE.GET({ fileId: data.imageId })
|
? { uri: API_STRORAGE.GET({ fileId: data.imageId }) }
|
||||||
: DUMMY_IMAGE.avatar
|
: DUMMY_IMAGE.avatar
|
||||||
}
|
}
|
||||||
|
style={{ width: 200, height: 200 }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
AvatarCustom,
|
BaseBox,
|
||||||
ButtonCenteredOnly,
|
ButtonCenteredOnly,
|
||||||
ButtonCustom,
|
ButtonCustom,
|
||||||
SelectCustom,
|
SelectCustom,
|
||||||
@@ -10,16 +10,23 @@ import {
|
|||||||
} 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 { apiCreateProfile } from "@/service/api-client/api-profile";
|
||||||
import { router, useFocusEffect } from "expo-router";
|
import { apiValidationEmail } from "@/service/api-client/api-validation";
|
||||||
import { useCallback, useState } from "react";
|
import { uploadImageService } from "@/service/upload-service";
|
||||||
import { View } from "react-native";
|
import pickImage from "@/utils/pickImage";
|
||||||
|
import { router } from "expo-router";
|
||||||
|
import { 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 +37,11 @@ export default function CreateProfile() {
|
|||||||
jenisKelamin: "",
|
jenisKelamin: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
useFocusEffect(
|
|
||||||
useCallback(() => {
|
|
||||||
Toast.show({
|
|
||||||
type: "info",
|
|
||||||
text1: "Lengkapi Profile Anda",
|
|
||||||
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 +53,67 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imagePhoto) {
|
||||||
|
try {
|
||||||
|
const responseUploadPhoto = await uploadImageService({
|
||||||
|
imageUri: imagePhoto,
|
||||||
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (responseUploadPhoto.success) {
|
||||||
|
const fileIdPhoto = responseUploadPhoto.data.id;
|
||||||
|
|
||||||
|
IMG.imageId = fileIdPhoto;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Gagal",
|
||||||
|
text2: error as string,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageBackground) {
|
||||||
|
try {
|
||||||
|
const responseUploadBackground = await uploadImageService({
|
||||||
|
imageUri: imageBackground,
|
||||||
|
dirId: DIRECTORY_ID.profile_background,
|
||||||
|
});
|
||||||
|
if (responseUploadBackground.success) {
|
||||||
|
const fileIdBackground = responseUploadBackground.data.id;
|
||||||
|
|
||||||
|
IMG.imageBackgroundId = fileIdBackground;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Gagal",
|
||||||
|
text2: error as string,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,9 +128,15 @@ export default function CreateProfile() {
|
|||||||
text1: "Sukses",
|
text1: "Sukses",
|
||||||
text2: "Profile berhasil dibuat",
|
text2: "Profile berhasil dibuat",
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Gagal membuat profile",
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -92,11 +159,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 +180,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>
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export default function ScreenUpload() {
|
|||||||
dirId: DIRECTORY_ID.profile_foto,
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Response", JSON.stringify(response, null, 2));
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
await AsyncStorage.setItem("idImage", response.data.id);
|
await AsyncStorage.setItem("idImage", response.data.id);
|
||||||
router.back();
|
router.back();
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 395 KiB After Width: | Height: | Size: 30 KiB |
BIN
assets/images/loading.gif
Normal file
BIN
assets/images/loading.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
59
components/Image/AvatarComp.tsx
Normal file
59
components/Image/AvatarComp.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
||||||
|
import DUMMY_IMAGE from "@/constants/dummy-image-value";
|
||||||
|
import { Href, router } from "expo-router";
|
||||||
|
import { TouchableOpacity } from "react-native";
|
||||||
|
import { Avatar } from "react-native-paper";
|
||||||
|
|
||||||
|
type Size = "base" | "sm" | "md" | "lg" | "xl";
|
||||||
|
|
||||||
|
const sizeMap = {
|
||||||
|
base: 40,
|
||||||
|
sm: 60,
|
||||||
|
md: 80,
|
||||||
|
lg: 100,
|
||||||
|
xl: 120,
|
||||||
|
};
|
||||||
|
|
||||||
|
interface AvatarCompProps {
|
||||||
|
fileId?: string;
|
||||||
|
size: Size;
|
||||||
|
onPress?: () => void | any;
|
||||||
|
href?: Href | undefined | any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AvatarComp({
|
||||||
|
fileId,
|
||||||
|
size,
|
||||||
|
onPress,
|
||||||
|
href = `/(application)/(image)/preview-image/${fileId}`,
|
||||||
|
}: AvatarCompProps) {
|
||||||
|
const dimension = sizeMap[size];
|
||||||
|
|
||||||
|
const avatarImage = () => {
|
||||||
|
return (
|
||||||
|
<Avatar.Image
|
||||||
|
size={dimension}
|
||||||
|
source={
|
||||||
|
fileId ? { uri: API_STRORAGE.GET({ fileId }) } : DUMMY_IMAGE.avatar
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{onPress || href ? (
|
||||||
|
<TouchableOpacity
|
||||||
|
activeOpacity={0.9}
|
||||||
|
onPress={
|
||||||
|
href && fileId ? () => router.navigate(href as any) : onPress
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{avatarImage()}
|
||||||
|
</TouchableOpacity>
|
||||||
|
) : (
|
||||||
|
avatarImage()
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -14,8 +14,8 @@ type Size = "base" | "sm" | "md" | "lg" | "xl";
|
|||||||
interface AvatarCustomProps {
|
interface AvatarCustomProps {
|
||||||
source?: ImageSourcePropType;
|
source?: ImageSourcePropType;
|
||||||
size?: Size;
|
size?: Size;
|
||||||
onPress?: () => void;
|
onPress?: () => any;
|
||||||
href?: Href | undefined;
|
href?: Href | undefined | any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sizeMap = {
|
const sizeMap = {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ export default function IconEdit({
|
|||||||
size,
|
size,
|
||||||
color,
|
color,
|
||||||
}: {
|
}: {
|
||||||
size: number;
|
size?: number;
|
||||||
color: string;
|
color?: string;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import StackCustom from "./Stack/StackCustom";
|
|||||||
import SelectCustom from "./Select/SelectCustom";
|
import SelectCustom from "./Select/SelectCustom";
|
||||||
// Image
|
// Image
|
||||||
import AvatarCustom from "./Image/AvatarCustom";
|
import AvatarCustom from "./Image/AvatarCustom";
|
||||||
|
import AvatarComp from "./Image/AvatarComp";
|
||||||
import LandscapeFrameUploaded from "./Image/LandscapeFrameUploaded";
|
import LandscapeFrameUploaded from "./Image/LandscapeFrameUploaded";
|
||||||
// Divider
|
// Divider
|
||||||
import Divider from "./Divider/Divider";
|
import Divider from "./Divider/Divider";
|
||||||
@@ -69,6 +70,7 @@ export {
|
|||||||
AlertDefaultSystem,
|
AlertDefaultSystem,
|
||||||
// Image
|
// Image
|
||||||
AvatarCustom,
|
AvatarCustom,
|
||||||
|
AvatarComp,
|
||||||
// ShareComponent
|
// ShareComponent
|
||||||
AvatarUsernameAndOtherComponent,
|
AvatarUsernameAndOtherComponent,
|
||||||
// Button
|
// Button
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { AvatarCustom, ClickableCustom } from "@/components";
|
import { AvatarComp, ClickableCustom } from "@/components";
|
||||||
|
import API_STRORAGE from "@/constants/base-url-api-strorage";
|
||||||
import { AccentColor } from "@/constants/color-palet";
|
import { AccentColor } from "@/constants/color-palet";
|
||||||
import DUMMY_IMAGE from "@/constants/dummy-image-value";
|
import DUMMY_IMAGE from "@/constants/dummy-image-value";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
@@ -12,8 +13,6 @@ const AvatarAndBackground = ({
|
|||||||
imageId: string;
|
imageId: string;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
// console.log("backgroundId", backgroundId),
|
|
||||||
// console.log("imageId", imageId),
|
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
{/* Background Image */}
|
{/* Background Image */}
|
||||||
<ClickableCustom
|
<ClickableCustom
|
||||||
@@ -24,24 +23,19 @@ const AvatarAndBackground = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ImageBackground
|
<ImageBackground
|
||||||
source={DUMMY_IMAGE.background}
|
source={
|
||||||
|
backgroundId
|
||||||
|
? { uri: API_STRORAGE.GET({ fileId: backgroundId }) }
|
||||||
|
: DUMMY_IMAGE.background
|
||||||
|
}
|
||||||
style={styles.backgroundImage}
|
style={styles.backgroundImage}
|
||||||
resizeMode="cover"
|
resizeMode="cover"
|
||||||
/>
|
/>
|
||||||
</ClickableCustom>
|
</ClickableCustom>
|
||||||
|
|
||||||
{/* Avatar yang sedikit keluar */}
|
{/* Avatar yang sedikit keluar */}
|
||||||
|
|
||||||
<View style={styles.avatarOverlap}>
|
<View style={styles.avatarOverlap}>
|
||||||
<ClickableCustom
|
<AvatarComp size="lg" fileId={imageId} />
|
||||||
onPress={() => {
|
|
||||||
router.navigate(
|
|
||||||
`/(application)/(image)/preview-image/${imageId}`
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<AvatarCustom source={DUMMY_IMAGE.avatar} size="lg" />
|
|
||||||
</ClickableCustom>
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ export default function ProfileSection({ data }: { data: IProfile }) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BaseBox>
|
<BaseBox>
|
||||||
{/* <TextCustom>
|
|
||||||
{JSON.stringify(data.imageBackgroundId, null, 2)}
|
|
||||||
</TextCustom> */}
|
|
||||||
<AvatarAndBackground
|
<AvatarAndBackground
|
||||||
backgroundId={data?.imageBackgroundId as any}
|
backgroundId={data?.imageBackgroundId as any}
|
||||||
imageId={data?.imageId as any}
|
imageId={data?.imageId as any}
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ export async function apiProfile({ id }: { id: string }) {
|
|||||||
export async function apiUpdateProfile({
|
export async function apiUpdateProfile({
|
||||||
id,
|
id,
|
||||||
data,
|
data,
|
||||||
|
category,
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
id: string;
|
||||||
data: any;
|
data: any;
|
||||||
|
category: "profile" | "photo" | "background";
|
||||||
}) {
|
}) {
|
||||||
const response = await apiConfig.put(`/mobile/profile/${id}`, {
|
const response = await apiConfig.put(`/mobile/profile/${id}?category=${category}`, {
|
||||||
data: data,
|
data: data,
|
||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
@@ -29,7 +29,6 @@ apiConfig.interceptors.request.use(
|
|||||||
export async function apiVersion() {
|
export async function apiVersion() {
|
||||||
// console.log("API_BASE_URL", API_BASE_URL);
|
// console.log("API_BASE_URL", API_BASE_URL);
|
||||||
const response = await apiConfig.get("/version");
|
const response = await apiConfig.get("/version");
|
||||||
// console.log("Response version", JSON.stringify(response.data, null, 2));
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
import { API_BASE_URL } from "@/service/api-config";
|
||||||
import { API_BASE_URL, apiConfig } from "@/service/api-config";
|
|
||||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Toast from "react-native-toast-message";
|
|
||||||
|
|
||||||
export async function uploadImageService({
|
export async function uploadImageService({
|
||||||
dirId,
|
dirId,
|
||||||
@@ -17,12 +15,7 @@ export async function uploadImageService({
|
|||||||
console.log("url >>", url);
|
console.log("url >>", url);
|
||||||
|
|
||||||
if (!imageUri) {
|
if (!imageUri) {
|
||||||
Toast.show({
|
throw new Error("Harap pilih gambar terlebih dahulu");
|
||||||
type: "error",
|
|
||||||
text1: "Gagal",
|
|
||||||
text2: "Harap pilih gambar terlebih dahulu",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -40,39 +33,22 @@ export async function uploadImageService({
|
|||||||
});
|
});
|
||||||
formData.append("dirId", dirId);
|
formData.append("dirId", dirId);
|
||||||
|
|
||||||
console.log("Form data >>", JSON.stringify(formData, null, 2));
|
|
||||||
|
|
||||||
const response = await axios.post(url, formData, {
|
const response = await axios.post(url, formData, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
timeout: 30000,
|
// timeout: 30000,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Response", JSON.stringify(response, null, 2));
|
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
Toast.show({
|
throw new Error(data.message);
|
||||||
type: "error",
|
|
||||||
text1: "Gagal",
|
|
||||||
text2: data.message,
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.show({
|
|
||||||
type: "success",
|
|
||||||
text1: "File berhasil diunggah",
|
|
||||||
});
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Toast.show({
|
throw error;
|
||||||
type: "error",
|
|
||||||
text1: "File gagal diunggah",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user