> > Deskripsi: > - list task divisi > - pencarian task divisi > - detail task divisi > - update status tugas task divisi > - detail tugas task divisi > - edit tugas task divisi > - hapus tugas task divisi > - hapus file task divisi > - hapus member > - tambah tugas task divisi > - check file task divisi > - tambah file task divisi > - edit task divisi > - cancel task divisi > - tambah member task divisi > > No Issues
124 lines
3.7 KiB
TypeScript
124 lines
3.7 KiB
TypeScript
import ButtonBackHeader from "@/components/buttonBackHeader";
|
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
|
import { InputForm } from "@/components/inputForm";
|
|
import Styles from "@/constants/Styles";
|
|
import { apiEditTask, apiGetTaskOne } from "@/lib/api";
|
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
|
import { useAuthSession } from "@/providers/AuthProvider";
|
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
|
import { useEffect, useState } from "react";
|
|
import { SafeAreaView, ScrollView, ToastAndroid, View } from "react-native";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
export default function TaskDivisionEdit() {
|
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
|
const { token, decryptToken } = useAuthSession();
|
|
const [judul, setJudul] = useState("");
|
|
const [error, setError] = useState(false);
|
|
const [disable, setDisable] = useState(false);
|
|
const dispatch = useDispatch();
|
|
const update = useSelector((state: any) => state.taskUpdate);
|
|
|
|
async function handleLoad() {
|
|
try {
|
|
const hasil = await decryptToken(String(token?.current));
|
|
const response = await apiGetTaskOne({
|
|
user: hasil,
|
|
cat: "data",
|
|
id: detail,
|
|
});
|
|
setJudul(response.data.title);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
handleLoad();
|
|
}, []);
|
|
|
|
function onValidation(val: string) {
|
|
setJudul(val);
|
|
if (val == "" || val == "null") {
|
|
setError(true);
|
|
}else{
|
|
setError(false);
|
|
}
|
|
}
|
|
|
|
function checkAll() {
|
|
if (judul == "" || judul == "null" || error) {
|
|
setDisable(true);
|
|
} else {
|
|
setDisable(false);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
checkAll();
|
|
}, [judul, error]);
|
|
|
|
async function handleUpdate() {
|
|
try {
|
|
const hasil = await decryptToken(String(token?.current));
|
|
const response = await apiEditTask(
|
|
{
|
|
title: judul,
|
|
user: hasil,
|
|
},
|
|
detail
|
|
);
|
|
if (response.success) {
|
|
dispatch(setUpdateTask({ ...update, data: !update.data }));
|
|
ToastAndroid.show("Berhasil mengubah data", ToastAndroid.SHORT);
|
|
router.back();
|
|
} else {
|
|
ToastAndroid.show(response.message, ToastAndroid.SHORT);
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView>
|
|
<Stack.Screen
|
|
options={{
|
|
headerLeft: () => (
|
|
<ButtonBackHeader
|
|
onPress={() => {
|
|
router.back();
|
|
}}
|
|
/>
|
|
),
|
|
headerTitle: "Edit Judul",
|
|
headerTitleAlign: "center",
|
|
headerRight: () => (
|
|
<ButtonSaveHeader
|
|
category="update"
|
|
disable={disable}
|
|
onPress={() => { handleUpdate() }}
|
|
/>
|
|
),
|
|
}}
|
|
/>
|
|
<ScrollView>
|
|
<View style={[Styles.p15, Styles.mb100]}>
|
|
<InputForm
|
|
label="Judul Kegiatan"
|
|
type="default"
|
|
placeholder="Judul Kegiatan"
|
|
required
|
|
bg="white"
|
|
value={judul}
|
|
onChange={(val) => { onValidation(val) }}
|
|
error={error}
|
|
errorText="Judul Kegiatan harus diisi"
|
|
/>
|
|
</View>
|
|
</ScrollView>
|
|
</SafeAreaView>
|
|
);
|
|
}
|