Forum
Add: - api-client/api-forum Fix: - Integrasi API: create dan beranda file ### No Issue
This commit is contained in:
@@ -4,18 +4,47 @@ import {
|
|||||||
TextAreaCustom,
|
TextAreaCustom,
|
||||||
ViewWrapper,
|
ViewWrapper,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
|
import { apiForumCreate } from "@/service/api-client/api-forum";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function ForumCreate() {
|
export default function ForumCreate() {
|
||||||
|
const { user } = useAuth();
|
||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const handlerSubmit = async () => {
|
||||||
|
const newData = {
|
||||||
|
diskusi: text,
|
||||||
|
authorId: user?.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const response = await apiForumCreate({ data: newData });
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: "Posting berhasil",
|
||||||
|
});
|
||||||
|
setText("");
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const buttonFooter = (
|
const buttonFooter = (
|
||||||
<BoxButtonOnFooter>
|
<BoxButtonOnFooter>
|
||||||
<ButtonCustom
|
<ButtonCustom
|
||||||
|
isLoading={isLoading}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
console.log("Posting", text);
|
handlerSubmit();
|
||||||
router.back();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Posting
|
Posting
|
||||||
|
|||||||
@@ -1,25 +1,58 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import {
|
import {
|
||||||
AlertCustom,
|
AvatarComp,
|
||||||
AvatarCustom,
|
|
||||||
BackButton,
|
BackButton,
|
||||||
DrawerCustom,
|
DrawerCustom,
|
||||||
|
LoaderCustom,
|
||||||
SearchInput,
|
SearchInput,
|
||||||
|
TextCustom,
|
||||||
ViewWrapper,
|
ViewWrapper,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import FloatingButton from "@/components/Button/FloatingButton";
|
import FloatingButton from "@/components/Button/FloatingButton";
|
||||||
import { MainColor } from "@/constants/color-palet";
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
import Forum_BoxDetailSection from "@/screens/Forum/DiscussionBoxSection";
|
import Forum_BoxDetailSection from "@/screens/Forum/DiscussionBoxSection";
|
||||||
import { listDummyDiscussionForum } from "@/screens/Forum/list-data-dummy";
|
|
||||||
import Forum_MenuDrawerBerandaSection from "@/screens/Forum/MenuDrawerSection.tsx/MenuBeranda";
|
import Forum_MenuDrawerBerandaSection from "@/screens/Forum/MenuDrawerSection.tsx/MenuBeranda";
|
||||||
import { router, Stack } from "expo-router";
|
import { apiForumGetAll } from "@/service/api-client/api-forum";
|
||||||
import { useState } from "react";
|
import { apiUser } from "@/service/api-client/api-user";
|
||||||
|
import { router, Stack, useFocusEffect } from "expo-router";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
export default function Forum() {
|
export default function Forum() {
|
||||||
const id = "test-id-forum";
|
const id = "test-id-forum";
|
||||||
const [openDrawer, setOpenDrawer] = useState(false);
|
const [openDrawer, setOpenDrawer] = useState(false);
|
||||||
const [status, setStatus] = useState("");
|
const [status, setStatus] = useState("");
|
||||||
const [alertStatus, setAlertStatus] = useState(false);
|
const { user } = useAuth();
|
||||||
const [deleteAlert, setDeleteAlert] = useState(false);
|
const [dataUser, setDataUser] = useState<any>();
|
||||||
|
const [listData, setListData] = useState<any[]>();
|
||||||
|
const [loadingGetList, setLoadingGetList] = useState(false);
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
onLoadData();
|
||||||
|
onLoadDataProfile(user?.id as string);
|
||||||
|
}, [user?.id, search])
|
||||||
|
);
|
||||||
|
|
||||||
|
const onLoadDataProfile = async (id: string) => {
|
||||||
|
const response = await apiUser(id);
|
||||||
|
setDataUser(response.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onLoadData = async () => {
|
||||||
|
try {
|
||||||
|
setLoadingGetList(true);
|
||||||
|
const response = await apiForumGetAll({ search: search });
|
||||||
|
console.log("[DATA PROFILE]", JSON.stringify(response.data, null, 2));
|
||||||
|
|
||||||
|
setListData(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
} finally {
|
||||||
|
setLoadingGetList(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -27,12 +60,23 @@ export default function Forum() {
|
|||||||
options={{
|
options={{
|
||||||
title: "Forum",
|
title: "Forum",
|
||||||
headerLeft: () => <BackButton />,
|
headerLeft: () => <BackButton />,
|
||||||
headerRight: () => <AvatarCustom href={`/forum/${id}/forumku`} />,
|
headerRight: () => (
|
||||||
|
<AvatarComp
|
||||||
|
fileId={dataUser?.Profile?.imageId}
|
||||||
|
size="base"
|
||||||
|
href={`/forum/${user?.id}/forumku`}
|
||||||
|
/>
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ViewWrapper
|
<ViewWrapper
|
||||||
headerComponent={<SearchInput placeholder="Cari topik diskusi" />}
|
headerComponent={
|
||||||
|
<SearchInput
|
||||||
|
placeholder="Cari topik diskusi"
|
||||||
|
onChangeText={(e) => setSearch(e)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
floatingButton={
|
floatingButton={
|
||||||
<FloatingButton
|
<FloatingButton
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
@@ -41,7 +85,14 @@ export default function Forum() {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{listDummyDiscussionForum.map((e, i) => (
|
{loadingGetList ? (
|
||||||
|
<LoaderCustom />
|
||||||
|
) : _.isEmpty(listData) ? (
|
||||||
|
<TextCustom align="center" color="gray">
|
||||||
|
Tidak ada diskusi
|
||||||
|
</TextCustom>
|
||||||
|
) : (
|
||||||
|
listData?.map((e: any, i: number) => (
|
||||||
<Forum_BoxDetailSection
|
<Forum_BoxDetailSection
|
||||||
key={i}
|
key={i}
|
||||||
data={e}
|
data={e}
|
||||||
@@ -50,11 +101,12 @@ export default function Forum() {
|
|||||||
isTruncate={true}
|
isTruncate={true}
|
||||||
href={`/forum/${id}`}
|
href={`/forum/${id}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))
|
||||||
|
)}
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
|
|
||||||
<DrawerCustom
|
<DrawerCustom
|
||||||
height={350}
|
height={"auto"}
|
||||||
isVisible={openDrawer}
|
isVisible={openDrawer}
|
||||||
closeDrawer={() => setOpenDrawer(false)}
|
closeDrawer={() => setOpenDrawer(false)}
|
||||||
>
|
>
|
||||||
@@ -64,13 +116,13 @@ export default function Forum() {
|
|||||||
setIsDrawerOpen={() => {
|
setIsDrawerOpen={() => {
|
||||||
setOpenDrawer(false);
|
setOpenDrawer(false);
|
||||||
}}
|
}}
|
||||||
setShowDeleteAlert={setDeleteAlert}
|
setShowDeleteAlert={() => {}}
|
||||||
setShowAlertStatus={setAlertStatus}
|
setShowAlertStatus={() => {}}
|
||||||
/>
|
/>
|
||||||
</DrawerCustom>
|
</DrawerCustom>
|
||||||
|
|
||||||
{/* Alert Status */}
|
{/* Alert Status */}
|
||||||
<AlertCustom
|
{/* <AlertCustom
|
||||||
isVisible={alertStatus}
|
isVisible={alertStatus}
|
||||||
title="Ubah Status Forum"
|
title="Ubah Status Forum"
|
||||||
message="Apakah Anda yakin ingin mengubah status forum ini?"
|
message="Apakah Anda yakin ingin mengubah status forum ini?"
|
||||||
@@ -87,10 +139,10 @@ export default function Forum() {
|
|||||||
textLeft="Batal"
|
textLeft="Batal"
|
||||||
textRight="Ubah"
|
textRight="Ubah"
|
||||||
colorRight={MainColor.green}
|
colorRight={MainColor.green}
|
||||||
/>
|
/> */}
|
||||||
|
|
||||||
{/* Alert Delete */}
|
{/* Alert Delete */}
|
||||||
<AlertCustom
|
{/* <AlertCustom
|
||||||
isVisible={deleteAlert}
|
isVisible={deleteAlert}
|
||||||
title="Hapus Forum"
|
title="Hapus Forum"
|
||||||
message="Apakah Anda yakin ingin menghapus forum ini?"
|
message="Apakah Anda yakin ingin menghapus forum ini?"
|
||||||
@@ -107,7 +159,7 @@ export default function Forum() {
|
|||||||
textLeft="Batal"
|
textLeft="Batal"
|
||||||
textRight="Hapus"
|
textRight="Hapus"
|
||||||
colorRight={MainColor.red}
|
colorRight={MainColor.red}
|
||||||
/>
|
/> */}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
AvatarCustom,
|
AvatarComp,
|
||||||
BaseBox,
|
BaseBox,
|
||||||
ClickableCustom,
|
ClickableCustom,
|
||||||
Grid,
|
Grid,
|
||||||
Spacing,
|
Spacing,
|
||||||
TextCustom,
|
TextCustom
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import { MainColor } from "@/constants/color-palet";
|
import { MainColor } from "@/constants/color-palet";
|
||||||
import { ICON_SIZE_SMALL } from "@/constants/constans-value";
|
import { ICON_SIZE_SMALL } from "@/constants/constans-value";
|
||||||
@@ -31,12 +31,13 @@ export default function Forum_BoxDetailSection({
|
|||||||
backgroundColor: MainColor.soft_darkblue,
|
backgroundColor: MainColor.soft_darkblue,
|
||||||
padding: 8,
|
padding: 8,
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
|
paddingBlock: 20,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isTruncate ? (
|
{isTruncate ? (
|
||||||
<TextCustom truncate={2}>{data.deskripsi}</TextCustom>
|
<TextCustom truncate={2}>{data?.diskusi}</TextCustom>
|
||||||
) : (
|
) : (
|
||||||
<TextCustom>{data.deskripsi}</TextCustom>
|
<TextCustom>{data?.diskusi}</TextCustom>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -47,17 +48,21 @@ export default function Forum_BoxDetailSection({
|
|||||||
<View>
|
<View>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={2}>
|
<Grid.Col span={2}>
|
||||||
<AvatarCustom href={`/profile/${data.id}`} />
|
<AvatarComp
|
||||||
|
fileId={data?.Author?.Profile?.imageId}
|
||||||
|
href={`/profile/${data?.Author?.Profile?.id}`}
|
||||||
|
size={"base"}
|
||||||
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={8}>
|
<Grid.Col span={8}>
|
||||||
<TextCustom>{data.name}</TextCustom>
|
<TextCustom>{data?.Author?.username}</TextCustom>
|
||||||
{data.status === "Open" ? (
|
{data?.ForumMaster_StatusPosting?.status === "Open" ? (
|
||||||
<TextCustom bold size="small" color="green">
|
<TextCustom bold size="small" color="green">
|
||||||
{data.status}
|
{data?.ForumMaster_StatusPosting?.status}
|
||||||
</TextCustom>
|
</TextCustom>
|
||||||
) : (
|
) : (
|
||||||
<TextCustom bold size="small" color="red">
|
<TextCustom bold size="small" color="red">
|
||||||
{data.status}
|
{data?.ForumMaster_StatusPosting?.status}
|
||||||
</TextCustom>
|
</TextCustom>
|
||||||
)}
|
)}
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -71,7 +76,7 @@ export default function Forum_BoxDetailSection({
|
|||||||
<ClickableCustom
|
<ClickableCustom
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setOpenDrawer(true);
|
setOpenDrawer(true);
|
||||||
setStatus(data.status);
|
setStatus(data?.ForumMaster_StatusPosting?.status);
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
alignItems: "flex-end",
|
alignItems: "flex-end",
|
||||||
@@ -86,6 +91,7 @@ export default function Forum_BoxDetailSection({
|
|||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
{href ? (
|
{href ? (
|
||||||
<ClickableCustom onPress={() => router.push(href as any)}>
|
<ClickableCustom onPress={() => router.push(href as any)}>
|
||||||
{deskripsiView}
|
{deskripsiView}
|
||||||
@@ -110,7 +116,7 @@ export default function Forum_BoxDetailSection({
|
|||||||
size={ICON_SIZE_SMALL}
|
size={ICON_SIZE_SMALL}
|
||||||
color={MainColor.white}
|
color={MainColor.white}
|
||||||
/>
|
/>
|
||||||
<TextCustom>{data.jumlahBalas}</TextCustom>
|
<TextCustom>{data?.Forum_Komentar?.length}</TextCustom>
|
||||||
</View>
|
</View>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={6} style={{ alignItems: "flex-end" }}>
|
<Grid.Col span={6} style={{ alignItems: "flex-end" }}>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IMenuDrawerItem } from "@/components/_Interface/types";
|
|||||||
import MenuDrawerDynamicGrid from "@/components/Drawer/MenuDrawerDynamicGird";
|
import MenuDrawerDynamicGrid from "@/components/Drawer/MenuDrawerDynamicGird";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { drawerItemsForumBeranda } from "../ListPage";
|
import { drawerItemsForumBeranda } from "../ListPage";
|
||||||
|
import { AlertDefaultSystem } from "@/components";
|
||||||
|
|
||||||
export default function Forum_MenuDrawerBerandaSection({
|
export default function Forum_MenuDrawerBerandaSection({
|
||||||
id,
|
id,
|
||||||
@@ -13,14 +14,26 @@ export default function Forum_MenuDrawerBerandaSection({
|
|||||||
id: string;
|
id: string;
|
||||||
status: string;
|
status: string;
|
||||||
setIsDrawerOpen: (value: boolean) => void;
|
setIsDrawerOpen: (value: boolean) => void;
|
||||||
setShowDeleteAlert: (value: boolean) => void;
|
setShowDeleteAlert?: (value: boolean) => void;
|
||||||
setShowAlertStatus: (value: boolean) => void;
|
setShowAlertStatus?: (value: boolean) => void;
|
||||||
}) {
|
}) {
|
||||||
const handlePress = (item: IMenuDrawerItem) => {
|
const handlePress = (item: IMenuDrawerItem) => {
|
||||||
if (item.label === "Hapus") {
|
if (item.label === "Hapus") {
|
||||||
setShowDeleteAlert(true);
|
AlertDefaultSystem({
|
||||||
|
title: "Hapus",
|
||||||
|
message: "Apakah Anda yakin ingin menghapus forum ini?",
|
||||||
|
textLeft: "Batal",
|
||||||
|
textRight: "Hapus",
|
||||||
|
onPressRight: () => {},
|
||||||
|
});
|
||||||
} else if (item.label === "Buka forum" || item.label === "Tutup forum") {
|
} else if (item.label === "Buka forum" || item.label === "Tutup forum") {
|
||||||
setShowAlertStatus(true);
|
AlertDefaultSystem({
|
||||||
|
title: "Ubah Status",
|
||||||
|
message: "Apakah Anda yakin ingin mengubah status forum ini?",
|
||||||
|
textLeft: "Batal",
|
||||||
|
textRight: "Ubah",
|
||||||
|
onPressRight: () => {},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
router.push(item.path as any);
|
router.push(item.path as any);
|
||||||
}
|
}
|
||||||
@@ -34,7 +47,7 @@ export default function Forum_MenuDrawerBerandaSection({
|
|||||||
<MenuDrawerDynamicGrid
|
<MenuDrawerDynamicGrid
|
||||||
data={drawerItemsForumBeranda({ id, status })}
|
data={drawerItemsForumBeranda({ id, status })}
|
||||||
columns={4} // Ubah ke 2 jika ingin 2 kolom per baris
|
columns={4} // Ubah ke 2 jika ingin 2 kolom per baris
|
||||||
onPressItem={handlePress}
|
onPressItem={handlePress as any}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
21
service/api-client/api-forum.ts
Normal file
21
service/api-client/api-forum.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { apiConfig } from "../api-config";
|
||||||
|
|
||||||
|
export async function apiForumCreate({ data }: { data: any }) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.post(`/mobile/forum`, {
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function apiForumGetAll({search}: {search: string}) {
|
||||||
|
try {
|
||||||
|
const response = await apiConfig.get(`/mobile/forum?search=${search}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user