upd: revisi diskusi divisi
Deskripsi: - attachment file pada tambah diskusi divisi - attachment file pada edit diskus divisi - attachment file pada detail diskusi divisi No Issues
This commit is contained in:
@@ -135,6 +135,7 @@ export default function DetailDiscussionGeneral() {
|
|||||||
handleLoad('detail', false)
|
handleLoad('detail', false)
|
||||||
handleLoad('komentar', false)
|
handleLoad('komentar', false)
|
||||||
handleLoad('cek-anggota', false)
|
handleLoad('cek-anggota', false)
|
||||||
|
handleLoad('file', false)
|
||||||
}, [update]);
|
}, [update]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ export default function DiscussionDivisionEdit() {
|
|||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [fileForm, setFileForm] = useState<any[]>([])
|
const [fileForm, setFileForm] = useState<any[]>([])
|
||||||
const [isModalFile, setModalFile] = useState(false)
|
const [isModalFile, setModalFile] = useState(false)
|
||||||
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
||||||
|
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
||||||
|
|
||||||
|
|
||||||
async function handleLoad() {
|
async function handleLoad() {
|
||||||
try {
|
try {
|
||||||
@@ -37,6 +39,12 @@ export default function DiscussionDivisionEdit() {
|
|||||||
user: hasil,
|
user: hasil,
|
||||||
cat: "data",
|
cat: "data",
|
||||||
});
|
});
|
||||||
|
const response2 = await apiGetDiscussionOne({
|
||||||
|
id: detail,
|
||||||
|
user: hasil,
|
||||||
|
cat: "file",
|
||||||
|
});
|
||||||
|
setDataFile(response2.data);
|
||||||
setData(response.data.desc);
|
setData(response.data.desc);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -51,10 +59,26 @@ export default function DiscussionDivisionEdit() {
|
|||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiEditDiscussion({
|
const fd = new FormData()
|
||||||
data: { user: hasil, desc: data },
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
id: detail,
|
fd.append(`file${i}`, {
|
||||||
});
|
uri: fileForm[i].uri,
|
||||||
|
type: 'application/octet-stream',
|
||||||
|
name: fileForm[i].name,
|
||||||
|
} as any);
|
||||||
|
}
|
||||||
|
|
||||||
|
fd.append("data", JSON.stringify(
|
||||||
|
{
|
||||||
|
user: hasil, desc: data, oldFile: dataFile
|
||||||
|
}
|
||||||
|
))
|
||||||
|
const response = await apiEditDiscussion(fd, detail);
|
||||||
|
|
||||||
|
// const response = await apiEditDiscussion({
|
||||||
|
// data: { user: hasil, desc: data },
|
||||||
|
// id: detail,
|
||||||
|
// });
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
|
||||||
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
||||||
@@ -86,8 +110,18 @@ export default function DiscussionDivisionEdit() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function deleteFile(index: number) {
|
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
if (cat == "newFile") {
|
||||||
|
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
||||||
|
} else {
|
||||||
|
setDataFile(prev =>
|
||||||
|
prev.map(item =>
|
||||||
|
item.id === index
|
||||||
|
? { ...item, delete: true }
|
||||||
|
: item
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
setModalFile(false)
|
setModalFile(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,10 +163,22 @@ export default function DiscussionDivisionEdit() {
|
|||||||
|
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
||||||
{
|
{
|
||||||
fileForm.length > 0
|
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
|
||||||
&&
|
&&
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
||||||
|
{
|
||||||
|
dataFile.filter((val) => !val.delete).map((item, index) => (
|
||||||
|
<BorderBottomItem
|
||||||
|
key={index}
|
||||||
|
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
|
||||||
|
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
||||||
|
title={item.name + '.' + item.extension}
|
||||||
|
titleWeight="normal"
|
||||||
|
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
}
|
||||||
{
|
{
|
||||||
fileForm.map((item, index) => (
|
fileForm.map((item, index) => (
|
||||||
<BorderBottomItem
|
<BorderBottomItem
|
||||||
@@ -141,7 +187,7 @@ export default function DiscussionDivisionEdit() {
|
|||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
titleWeight="normal"
|
titleWeight="normal"
|
||||||
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -156,7 +202,7 @@ export default function DiscussionDivisionEdit() {
|
|||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash" color="black" size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => { deleteFile(indexDelFile.id, indexDelFile.cat) }}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|||||||
@@ -56,10 +56,18 @@ type PropsComment = {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type PropsFile = {
|
||||||
|
id: string;
|
||||||
|
idStorage: string;
|
||||||
|
name: string;
|
||||||
|
extension: string
|
||||||
|
}
|
||||||
|
|
||||||
export default function DiscussionDetail() {
|
export default function DiscussionDetail() {
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const [data, setData] = useState<Props>();
|
const [data, setData] = useState<Props>();
|
||||||
const [dataComment, setDataComment] = useState<PropsComment[]>([]);
|
const [dataComment, setDataComment] = useState<PropsComment[]>([]);
|
||||||
|
const [fileDiscussion, setFileDiscussion] = useState<PropsFile[]>([])
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [komentar, setKomentar] = useState("");
|
const [komentar, setKomentar] = useState("");
|
||||||
const [loadingSend, setLoadingSend] = useState(false);
|
const [loadingSend, setLoadingSend] = useState(false);
|
||||||
@@ -114,7 +122,15 @@ export default function DiscussionDetail() {
|
|||||||
user: hasil,
|
user: hasil,
|
||||||
cat: "data",
|
cat: "data",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const responseFile = await apiGetDiscussionOne({
|
||||||
|
id: detail,
|
||||||
|
user: hasil,
|
||||||
|
cat: "file",
|
||||||
|
});
|
||||||
|
|
||||||
setData(response.data);
|
setData(response.data);
|
||||||
|
setFileDiscussion(responseFile.data)
|
||||||
setIsCreator(response.data.createdBy == hasil);
|
setIsCreator(response.data.createdBy == hasil);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -290,6 +306,7 @@ export default function DiscussionDetail() {
|
|||||||
<SkeletonContent />
|
<SkeletonContent />
|
||||||
:
|
:
|
||||||
<BorderBottomItem2
|
<BorderBottomItem2
|
||||||
|
dataFile={fileDiscussion}
|
||||||
descEllipsize={false}
|
descEllipsize={false}
|
||||||
borderType="bottom"
|
borderType="bottom"
|
||||||
icon={
|
icon={
|
||||||
|
|||||||
@@ -54,7 +54,23 @@ export default function CreateDiscussionDivision() {
|
|||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiCreateDiscussion({ data: { user: hasil, desc, idDivision: id } })
|
const fd = new FormData()
|
||||||
|
|
||||||
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
|
fd.append(`file${i}`, {
|
||||||
|
uri: fileForm[i].uri,
|
||||||
|
type: 'application/octet-stream',
|
||||||
|
name: fileForm[i].name,
|
||||||
|
} as any);
|
||||||
|
}
|
||||||
|
|
||||||
|
fd.append("data", JSON.stringify(
|
||||||
|
{ user: hasil, desc, idDivision: id }
|
||||||
|
))
|
||||||
|
|
||||||
|
const response = await apiCreateDiscussion(fd)
|
||||||
|
|
||||||
|
// const response = await apiCreateDiscussion({ data: { user: hasil, desc, idDivision: id } })
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
||||||
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
||||||
|
|||||||
28
lib/api.ts
28
lib/api.ts
@@ -497,7 +497,7 @@ export const apiGetDiscussion = async ({ user, search, division, active, page }:
|
|||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiGetDiscussionOne = async ({ id, user, cat }: { id: string, user: string, cat: 'data' | 'comment' }) => {
|
export const apiGetDiscussionOne = async ({ id, user, cat }: { id: string, user: string, cat: 'data' | 'comment' | 'file' }) => {
|
||||||
const response = await api.get(`mobile/discussion/${id}?user=${user}&cat=${cat}`);
|
const response = await api.get(`mobile/discussion/${id}?user=${user}&cat=${cat}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
@@ -517,8 +517,17 @@ export const apiDeleteDiscussionCommentar = async ({ data, id }: { data: { user:
|
|||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiEditDiscussion = async ({ data, id }: { data: { user: string, desc: string }, id: string }) => {
|
// export const apiEditDiscussion = async ({ data, id }: { data: { user: string, desc: string }, id: string }) => {
|
||||||
const response = await api.post(`/mobile/discussion/${id}`, data)
|
// const response = await api.post(`/mobile/discussion/${id}`, data)
|
||||||
|
// return response.data;
|
||||||
|
// };
|
||||||
|
|
||||||
|
export const apiEditDiscussion = async (data: FormData, id: string) => {
|
||||||
|
const response = await api.post(`/mobile/discussion/${id}`, data, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
})
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -532,8 +541,17 @@ export const apiOpenCloseDiscussion = async (data: { user: string, status: numbe
|
|||||||
return response.data
|
return response.data
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiCreateDiscussion = async ({ data }: { data: { user: string, desc: string, idDivision: string } }) => {
|
// export const apiCreateDiscussion = async ({ data }: { data: { user: string, desc: string, idDivision: string } }) => {
|
||||||
const response = await api.post(`/mobile/discussion`, data)
|
// const response = await api.post(`/mobile/discussion`, data)
|
||||||
|
// return response.data;
|
||||||
|
// };
|
||||||
|
|
||||||
|
export const apiCreateDiscussion = async (data: FormData) => {
|
||||||
|
const response = await api.post(`/mobile/discussion`, data, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
})
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user