diff --git a/app/(application)/(user)/home.tsx b/app/(application)/(user)/home.tsx index bc1b36d..75ef4fb 100644 --- a/app/(application)/(user)/home.tsx +++ b/app/(application)/(user)/home.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable react-hooks/exhaustive-deps */ import { StackCustom, ViewWrapper } from "@/components"; import { MainColor } from "@/constants/color-palet"; @@ -8,31 +9,40 @@ import TabSection from "@/screens/Home/tabSection"; import { tabsHome } from "@/screens/Home/tabsList"; import Home_FeatureSection from "@/screens/Home/topFeatureSection"; import { apiUser } from "@/service/api-client/api-user"; +import { apiVersion } from "@/service/api-config"; import { Ionicons } from "@expo/vector-icons"; import { Redirect, router, Stack } from "expo-router"; import { useEffect, useState } from "react"; export default function Application() { - const { user } = useAuth(); - const [data, setData] = useState({}); + const { token, user } = useAuth(); + + const [data, setData] = useState(); useEffect(() => { onLoadData(); + checkVersion(); }, []); async function onLoadData() { const response = await apiUser(user?.id as string); - console.log("User >>", JSON.stringify(response.data.username, null, 2)); - console.log("Profile Check >>", JSON.stringify(response.data.Profile.id, null, 2)); + console.log("Response profile >>", JSON.stringify(response?.data?.Profile, null, 2)); setData(response.data); } + const checkVersion = async () => { + const response = await apiVersion(); + console.log("Version >>", JSON.stringify(response.data, null, 2)); + }; + if (data && data?.active === false) { + console.log("User is not active"); return ; } if (data && data?.Profile === null) { + console.log("Profile is null"); return ; } @@ -40,7 +50,7 @@ export default function Application() { <> ( (null); const [bidangBisnis, setBidangBisnis] = useState([]); - const [selectBidangId, setSelectBidangId] = useState(""); const [subBidangBisnis, setSubBidangBisnis] = useState< IMasterSubBidangBisnis[] >([]); - // const [subBidangSelected, setSubBidangSelected] = useState([]); + const [selectedSubBidang, setSelectedSubBidang] = useState([]); const [listSubBidangSelected, setListSubBidangSelected] = useState([ { id: "", @@ -82,6 +87,7 @@ export default function PortofolioCreate() { useEffect(() => { onLoadMaster(); + onLoadMasterSubBidangBisnis(); }, []); const onLoadMaster = async () => { @@ -94,15 +100,23 @@ export default function PortofolioCreate() { } }; - const onLoadMasterSubBidangBisnis = async ({ id }: { id: string }) => { + const onLoadMasterSubBidangBisnis = async () => { try { - const response = await apiMasterSubBidangBisnis({ id: id }); + const response = await apiMasterSubBidangBisnis({}); setSubBidangBisnis(response.data); } catch (error) { + setSubBidangBisnis([]); console.log("Error onLoadMasterBidangBisnis", error); } }; + const handlerSelectedSubBidang = ({ id }: { id: string }) => { + const selectedList = subBidangBisnis?.filter( + (item) => (item?.masterBidangBisnisId as any) === id + ); + setSelectedSubBidang(selectedList as any[]); + }; + return ( { + const isSameBidang = data.masterBidangBisnisId === value; + + if (!isSameBidang) { + setListSubBidangSelected([{ id: "" }]); + } + setData({ ...(data as any), masterBidangBisnisId: value }); - setSelectBidangId(id as string); - onLoadMasterSubBidangBisnis({ id: value as string }); + handlerSelectedSubBidang({ id: value as string }); }} /> - {/* {listSubBidangSelected.map((item, index) => ( - - - ({ - label: item.name, - value: item.id, - }))} - value={data.sub_bidang_usaha} - onChange={(value) => { - setData({ ...(data as any), sub_bidang_usaha: value }); - setListSubBidangSelected([ - ...listSubBidangSelected, - { id: value as string }, - ]); - }} - /> - - - console.log("delete")}> - - - - + {listSubBidangSelected.map((item, index) => ( + { + const selectedValues = listSubBidangSelected.map((s) => s.id); + return ( + option.id === item.id || // biarkan tetap muncul kalau ini valuenya sendiri + !selectedValues.includes(option.id) + ); + }) + .map((e: any) => ({ + value: e.id, + label: e.name, + }))} + value={item.id || null} + onChange={(value) => { + const list = _.clone(listSubBidangSelected); + list[index].id = value as any; + setListSubBidangSelected(list); + }} + /> ))} - + + { + setListSubBidangSelected([ + ...listSubBidangSelected, + { id: "" }, + ]); + }} + icon={ + + } + size="xl" + /> + { + const list = _.clone(listSubBidangSelected); + list.pop(); + setListSubBidangSelected(list); + }} + icon={ + + } + size="xl" + /> + + + + + {/* ({ + label: item.name, + value: item.id, + }))} + value={null} + onChange={(value) => { + setData({ ...(data as any), masterBidangBisnisId: value }); + handlerSelectedSubBidang({ id: value as string }); + }} + /> */} + + {/* { setListSubBidangSelected([...listSubBidangSelected, { id: "" }]); }} diff --git a/app/(application)/(user)/portofolio/[id]/index.tsx b/app/(application)/(user)/portofolio/[id]/index.tsx index 3cbc8e6..730da98 100644 --- a/app/(application)/(user)/portofolio/[id]/index.tsx +++ b/app/(application)/(user)/portofolio/[id]/index.tsx @@ -40,14 +40,14 @@ export default function Portofolio() { const response = await apiGetOnePortofolio({ id: id }); console.log( "Response portofolio >>", - JSON.stringify(response.data.namaBisnis, null, 2) + JSON.stringify(response.data, null, 2) ); setData(response.data); } const userId = user?.id; - const userLoginId = data?.Profile?.User?.id; + const userLoginId = data?.Profile?.userId console.log("User ID >>", userId); console.log("User Login ID >>", userLoginId); @@ -75,7 +75,7 @@ export default function Portofolio() { {/* */} - + void; icon: React.ReactNode; size?: SizeType; + disabled?: boolean; }) { const sizeMap = { xs: 22, @@ -25,7 +27,7 @@ export default function ActionIcon({ const getSize = (size: SizeType): DimensionValue => { if (!size) return sizeMap.md; // Default to 'md' if size is undefined - if (typeof size === 'string' && size in sizeMap) { + if (typeof size === "string" && size in sizeMap) { return sizeMap[size as keyof typeof sizeMap]; } return size as DimensionValue; @@ -35,9 +37,10 @@ export default function ActionIcon({ return ( { + if (disabled) return; if (href) { router.push(href); } else { diff --git a/screens/Authentication/RegisterView.tsx b/screens/Authentication/RegisterView.tsx index 9f73c35..bba60ee 100644 --- a/screens/Authentication/RegisterView.tsx +++ b/screens/Authentication/RegisterView.tsx @@ -14,7 +14,6 @@ import Toast from "react-native-toast-message"; export default function RegisterView() { const { nomor } = useLocalSearchParams(); const [username, setUsername] = useState(""); - // const [loading, setLoading] = useState(false); const { registerUser, isLoading } = useAuth(); @@ -22,16 +21,22 @@ export default function RegisterView() { if (!nomor) { Toast.show({ type: "error", - text1: "Gagal", - text2: "Nomor tidak ditemukan", + text1: "Lengkapi nomor", }); return false; } if (!username) { Toast.show({ type: "error", - text1: "Gagal", - text2: "Username tidak boleh kosong", + text1: "Username tidak boleh kosong", + }); + return false; + } + + if (username.includes(" ")) { + Toast.show({ + type: "info", + text1: "Username tidak boleh mengandung spasi", }); return false; } @@ -42,9 +47,20 @@ export default function RegisterView() { const isValid = validasiData(); if (!isValid) return; + if (username.length < 5) { + Toast.show({ + type: "info", + text1: "Info", + text2: "Username minimal 5 karakter", + }); + return; + } + + const usernameLower = username.toLowerCase(); + await registerUser({ nomor: nomor as string, - username: username, + username: usernameLower, }); } @@ -73,6 +89,11 @@ export default function RegisterView() { placeholder="Masukkan username" value={username} onChangeText={(text) => setUsername(text)} + error={ + username.includes(" ") + ? "Username tidak boleh mengandung spasi" + : "" + } /> diff --git a/screens/Portofolio/ButtonCreatePortofolio.tsx b/screens/Portofolio/ButtonCreatePortofolio.tsx index df4156e..5ee1f3a 100644 --- a/screens/Portofolio/ButtonCreatePortofolio.tsx +++ b/screens/Portofolio/ButtonCreatePortofolio.tsx @@ -45,7 +45,9 @@ export default function Portofolio_ButtonCreate({ !data.masterBidangBisnisId || !data.alamatKantor || !data.tlpn || - !data.deskripsi + !data.deskripsi || + subBidangSelected.map((item) => item.id).includes("") || + subBidangSelected.map((item) => item.id).includes(null) ) { return false; } @@ -53,6 +55,10 @@ export default function Portofolio_ButtonCreate({ }; const handleCreatePortofolio = async () => { + console.log( + "Data sub bidang >>", + JSON.stringify(subBidangSelected, null, 2) + ); if (!validaasiData()) { Toast.show({ type: "info", @@ -90,18 +96,18 @@ export default function Portofolio_ButtonCreate({ youtube: dataMedsos.youtube, subBidang: subBidangSelected, }; - - try { - const response = await apiPortofolioCreate({ - data: newData, - }); - console.log("Response >>", JSON.stringify(response, null, 2)); - // return router.replace(`/maps/create`); - // return router.push(`/maps/create`); - return router.back(); - } catch (error) { - throw error; - } + const response = await apiPortofolioCreate({ + data: newData, + }); + console.log("Response >>", JSON.stringify(response, null, 2)); + // return router.replace(`/maps/create`); + // return router.push(`/maps/create`); + Toast.show({ + type: "success", + text1: "Sukses", + text2: "Data berhasil disimpan", + }); + return router.back(); } catch (error) { Toast.show({ type: "error", diff --git a/screens/Portofolio/DataPortofolio.tsx b/screens/Portofolio/DataPortofolio.tsx index 77d7479..73c4e08 100644 --- a/screens/Portofolio/DataPortofolio.tsx +++ b/screens/Portofolio/DataPortofolio.tsx @@ -17,7 +17,13 @@ import { FontAwesome, Ionicons } from "@expo/vector-icons"; import { router, useLocalSearchParams } from "expo-router"; import { View } from "react-native"; -export default function Portofolio_Data({ data }: { data: any }) { +export default function Portofolio_Data({ + data, + listSubBidang, +}: { + data: any; + listSubBidang: any[]; +}) { const { id } = useLocalSearchParams(); const listData = [ @@ -83,6 +89,8 @@ export default function Portofolio_Data({ data }: { data: any }) { // }, // ]; + console.log("List Sub Bidang >>", JSON.stringify(listSubBidang, null, 2)); + return ( <> @@ -137,20 +145,24 @@ export default function Portofolio_Data({ data }: { data: any }) { ))} - {/* - {listSubBidang.map((item, index) => ( + + {listSubBidang?.map((item, index) => ( - {item.icon} + - {item.label} + {item?.MasterSubBidangBisnis?.name || "-"} ))} - */} + diff --git a/service/api-client/api-master.ts b/service/api-client/api-master.ts index 70f1e74..6d8dc87 100644 --- a/service/api-client/api-master.ts +++ b/service/api-client/api-master.ts @@ -9,12 +9,14 @@ export async function apiMasterBidangBisnis() { } } -export async function apiMasterSubBidangBisnis({id}: {id: string}) { +export async function apiMasterSubBidangBisnis({ id }: { id?: string }) { try { - const response = await apiConfig.get(`/master/sub-bidang-bisnis/${id}`); + const selectBidangId = id ? `/${id}` : ""; + const response = await apiConfig.get( + `/master/sub-bidang-bisnis${selectBidangId}` + ); return response.data; } catch (error) { throw error; } } - diff --git a/types/Type-Master.ts b/types/Type-Master.ts index 7d16efa..d6c153c 100644 --- a/types/Type-Master.ts +++ b/types/Type-Master.ts @@ -14,4 +14,5 @@ export interface IMasterSubBidangBisnis { isActive: boolean; createdAt: string; updatedAt: string; + masterBidangBisnisId: string; }