Merge pull request #292 from bipproduction/amalia/07-okt-24

Amalia/07 okt 24
This commit is contained in:
Amalia
2024-10-07 18:21:18 +08:00
committed by GitHub
7 changed files with 212 additions and 185 deletions

View File

@@ -49,23 +49,30 @@ function ViewLogin() {
if (cekLogin.success) { if (cekLogin.success) {
const code = Math.floor(Math.random() * 1000) + 1000 const code = Math.floor(Math.random() * 1000) + 1000
setLoading(true) setLoading(true)
try {
const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then( JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then(
async (res) => { async (res) => {
if (res.status == 200) { if (res.status == 200) {
setValPhone(cekLogin.phone) setValPhone(cekLogin.phone)
setOTP(code) setOTP(code)
setUser(cekLogin.id) setUser(cekLogin.id)
setVerif(true) setVerif(true)
setLoading(false) setLoading(false)
toast.success('Kode verifikasi telah dikirim') toast.success('Kode verifikasi telah dikirim')
} else { } else {
toast.error('Internal Server Error') console.error(res.status)
setLoading(false) toast.error('Internal Server Error')
setLoading(false)
}
} }
} )
) } catch (error) {
console.error(error)
toast.error('Internal Server Error')
}finally{
setLoading(false)
}
} else { } else {
return toast.error(cekLogin.message) return toast.error(cekLogin.message)
} }

View File

@@ -14,26 +14,30 @@ export default function ViewVerification({ phone, otp, user }: IVerification) {
const [isLoading, setLoading] = useState(false) const [isLoading, setLoading] = useState(false)
async function onResend() { async function onResend() {
const code = Math.floor(Math.random() * 1000) + 1000 try {
const code = Math.floor(Math.random() * 1000) + 1000
const res = await fetch(`https://wa.wibudev.com/code?nom=${phone}&text=*DARMASABA*%0A%0A const res = await fetch(`https://wa.wibudev.com/code?nom=${phone}&text=*DARMASABA*%0A%0A
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`) JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`)
.then( .then(
async (res) => { async (res) => {
if (res.status == 200) { if (res.status == 200) {
toast.success('Kode verifikasi telah dikirim') toast.success('Kode verifikasi telah dikirim')
setOTP(code) setOTP(code)
} else { } else {
toast.error('Internal Server Error') toast.error('Internal Server Error')
}
} }
} );
); } catch (error) {
console.error(error)
toast.error('Internal Server Error')
}
} }
async function getVerification() { async function getVerification() {
setLoading(true) setLoading(true)
if (isOTP == inputOTP) { if (isOTP == inputOTP) {
const setCookies = await funSetCookies({ user: user }) const setCookies: any = await funSetCookies({ user: user })
if (setCookies.success) { if (setCookies.success) {
toast.success(setCookies.message) toast.success(setCookies.message)

View File

@@ -13,6 +13,7 @@ import { funCreateDiscussion } from "../lib/api_discussion";
export default function FormCreateDiscussion({ id }: { id: string }) { export default function FormCreateDiscussion({ id }: { id: string }) {
const [isValModal, setValModal] = useState(false) const [isValModal, setValModal] = useState(false)
const [loadingModal, setLoadingModal] = useState(false)
const router = useRouter() const router = useRouter()
const [isImg, setImg] = useState("") const [isImg, setImg] = useState("")
const param = useParams<{ id: string, detail: string }>() const param = useParams<{ id: string, detail: string }>()
@@ -50,26 +51,25 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
async function createDiscussion(val: boolean) { async function createDiscussion(val: boolean) {
try { try {
if (val) { setLoadingModal(true)
const response = await funCreateDiscussion({ const response = await funCreateDiscussion({
desc: isData.desc, desc: isData.desc,
idDivision: id idDivision: id
}) })
if (response.success) { if (response.success) {
setDataRealtime(response.notif) setDataRealtime(response.notif)
toast.success(response.message) toast.success(response.message)
router.push(`/division/${param.id}/discussion/`) router.push(`/division/${param.id}/discussion/`)
setValModal(false) } else {
} else { toast.error(response.message)
toast.error(response.message)
}
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
toast.error("Gagal menambahkan diskusi, coba lagi nanti"); toast.error("Gagal menambahkan diskusi, coba lagi nanti");
} finally { } finally {
setValModal(false) setValModal(false)
setLoadingModal(false)
} }
} }
@@ -94,12 +94,12 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
}} }}
value={isData.desc} value={isData.desc}
onChange={(e) => setData({ ...isData, desc: e.target.value })} onChange={(e) => setData({ ...isData, desc: e.target.value })}
onBlur={() => setTouched({ ...touched, desc: true })} // onBlur={() => setTouched({ ...touched, desc: true })}
error={ // error={
touched.desc && ( // touched.desc && (
isData.desc == "" ? "Form Tidak Boleh Kosong" : null // isData.desc == "" ? "Form Tidak Boleh Kosong" : null
) // )
} // }
/> />
</Box> </Box>
</Grid.Col> </Grid.Col>
@@ -130,9 +130,11 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
</Button> </Button>
</Box> </Box>
<LayoutModal opened={isValModal} onClose={() => setValModal(false)} <LayoutModal loading={loadingModal} opened={isValModal} onClose={() => setValModal(false)}
description="Apakah Anda yakin ingin menambah data?" description="Apakah Anda yakin ingin menambah data?"
onYes={(val) => { createDiscussion(val) }} /> onYes={(val) => {
createDiscussion(val)
}} />
</Box> </Box>
) )
} }

View File

@@ -12,6 +12,7 @@ import { useHookstate } from "@hookstate/core"
export default function FormEditDiscussion() { export default function FormEditDiscussion() {
const [isValModal, setValModal] = useState(false) const [isValModal, setValModal] = useState(false)
const [loadingModal, setLoadingModal] = useState(false)
const router = useRouter() const router = useRouter()
const param = useParams<{ id: string, detail: string }>() const param = useParams<{ id: string, detail: string }>()
const [isDataOne, setDataOne] = useState("") const [isDataOne, setDataOne] = useState("")
@@ -35,43 +36,43 @@ export default function FormEditDiscussion() {
} }
} }
async function fetchEditDiscussion(val: boolean) { async function fetchEditDiscussion() {
try { try {
if (val) { setLoadingModal(true)
const response = await funEditDiscussion(param.detail, { const response = await funEditDiscussion(param.detail, {
desc: isDataOne desc: isDataOne
}) })
if (response.success) { if (response.success) {
toast.success(response.message) toast.success(response.message)
setValModal(false) setValModal(false)
router.push(`/division/${param.id}/discussion/${param.detail}`) router.push(`/division/${param.id}/discussion/${param.detail}`)
} else { } else {
toast.error(response.message) toast.error(response.message)
}
} }
setValModal(false)
} catch (error) { } catch (error) {
console.error(error); console.error(error);
setValModal(false) setValModal(false)
toast.error("Gagal menambahkan diskusi, coba lagi nanti"); toast.error("Gagal menambahkan diskusi, coba lagi nanti");
} finally { } finally {
setValModal(false) setValModal(false)
setLoadingModal(false)
} }
} }
async function getData() { async function getData() {
try { try {
setLoading(true) setLoading(true)
const res = await funGetProfileByCookies() const res = await funGetProfileByCookies()
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`) setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`)
setLoading(false) setLoading(false)
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {
setLoading(false) setLoading(false)
} }
} }
useShallowEffect(() => { useShallowEffect(() => {
fetchGetOneDiscussion() fetchGetOneDiscussion()
getData() getData()
@@ -84,43 +85,43 @@ export default function FormEditDiscussion() {
<Box p={20}> <Box p={20}>
<Grid gutter={0} pt={10}> <Grid gutter={0} pt={10}>
<Grid.Col span={2}> <Grid.Col span={2}>
{loading ? {loading ?
<Skeleton height={60} width={60} radius={100} /> <Skeleton height={60} width={60} radius={100} />
: :
<Avatar src={img} alt="it's me" size="lg" /> <Avatar src={img} alt="it's me" size="lg" />
} }
</Grid.Col> </Grid.Col>
<Grid.Col span={10}> <Grid.Col span={10}>
{loading ? {loading ?
Array(10) Array(10)
.fill(null) .fill(null)
.map((_, i) => ( .map((_, i) => (
<Box key={i} mb={20}> <Box key={i} mb={20}>
<Skeleton height={20} radius={10} /> <Skeleton height={20} radius={10} />
</Box> </Box>
)) ))
: :
<Box> <Box>
<Textarea <Textarea
placeholder="Tuliskan apa yang ingin anda diskusikan" placeholder="Tuliskan apa yang ingin anda diskusikan"
styles={{ styles={{
input: { input: {
border: 'none', border: 'none',
backgroundColor: 'transparent', backgroundColor: 'transparent',
height: "50vh" height: "50vh"
} }
}} }}
value={isDataOne} value={isDataOne}
onChange={(e) => setDataOne(e.target.value)} onChange={(e) => setDataOne(e.target.value)}
onBlur={() => setTouched({ ...touched, desc: true })} // onBlur={() => setTouched({ ...touched, desc: true })}
error={ // error={
touched.desc && ( // touched.desc && (
isDataOne == "" ? "Form Tidak Boleh Kosong" : null // isDataOne == "" ? "Form Tidak Boleh Kosong" : null
) // )
} // }
/> />
</Box> </Box>
} }
</Grid.Col> </Grid.Col>
</Grid> </Grid>
</Box> </Box>
@@ -153,9 +154,15 @@ export default function FormEditDiscussion() {
} }
</Box> </Box>
<LayoutModal opened={isValModal} onClose={() => setValModal(false)} <LayoutModal loading={loadingModal} opened={isValModal} onClose={() => setValModal(false)}
description="Apakah Anda yakin ingin mengubah data?" description="Apakah Anda yakin ingin mengubah data?"
onYes={(val) => { fetchEditDiscussion(val) }} /> onYes={(val) => {
if (val) {
fetchEditDiscussion()
} else {
setValModal(false)
}
}} />
</Box> </Box>
) )
} }

View File

@@ -1,25 +1,24 @@
"use client"; "use client";
import { keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global"; import { keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
import { Avatar, Box, Button, Center, Divider, Flex, Grid, Group, Input, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core"; import LayoutModal from "@/module/_global/layout/layout_modal";
import { useHookstate } from "@hookstate/core";
import { Avatar, Box, Button, Divider, Flex, Grid, Group, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
import { Dropzone } from '@mantine/dropzone';
import { useMediaQuery } from "@mantine/hooks";
import _ from "lodash";
import { useParams, useRouter } from "next/navigation"; import { useParams, useRouter } from "next/navigation";
import React, { useRef, useState } from "react"; import { useRef, useState } from "react";
import toast from "react-hot-toast";
import { FaTrash } from "react-icons/fa6";
import { IoIosArrowDropright } from "react-icons/io"; import { IoIosArrowDropright } from "react-icons/io";
import { BsFiletypeCsv } from "react-icons/bs"; import { useWibuRealtime } from "wibu-realtime";
import { funCreateTask } from "../lib/api_task";
import { IFormDateTask, IFormMemberTask, IListFileTask } from "../lib/type_task";
import { globalMemberTask } from "../lib/val_task";
import ViewDateEndTask from "./create_date_end_task";
import CreateUsersProject from "./create_users_project"; import CreateUsersProject from "./create_users_project";
import ResultsDateAndTask from "./results_date-and_task"; import ResultsDateAndTask from "./results_date-and_task";
import ResultsFile from "./results_file"; import ResultsFile from "./results_file";
import { useHookstate } from "@hookstate/core";
import { globalMemberTask } from "../lib/val_task";
import ViewDateEndTask from "./create_date_end_task";
import { IFormDateTask, IFormMemberTask, IListFileTask } from "../lib/type_task";
import { Dropzone } from '@mantine/dropzone';
import toast from "react-hot-toast";
import _ from "lodash";
import { FaTrash } from "react-icons/fa6";
import LayoutModal from "@/module/_global/layout/layout_modal";
import { funCreateTask } from "../lib/api_task";
import { useMediaQuery } from "@mantine/hooks";
import { useWibuRealtime } from "wibu-realtime";
export default function CreateTask() { export default function CreateTask() {
const router = useRouter() const router = useRouter()
@@ -44,8 +43,6 @@ export default function CreateTask() {
const tema = useHookstate(TEMA) const tema = useHookstate(TEMA)
const [touched, setTouched] = useState({ const [touched, setTouched] = useState({
title: false, title: false,
task: false,
member: false
}); });
const [data, setData] = useWibuRealtime({ const [data, setData] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu, WIBU_REALTIME_TOKEN: keyWibu,
@@ -103,6 +100,44 @@ export default function CreateTask() {
} }
function onCheck() {
const cek = checkAll()
if (!cek)
return false
if (dataTask.length == 0)
return toast.error("Error! silahkan tambahkan tugas")
if (memberValue.length == 0)
return toast.error("Error! silahkan pilih anggota")
setOpenModal(true)
}
function checkAll() {
let nilai = true
if (title === "") {
setTouched(touched => ({ ...touched, title: true }))
nilai = false
}
return nilai
}
function onValidation(kategori: string, val: string) {
if (kategori == 'title') {
setTitle(val)
if (val === "") {
setTouched({ ...touched, title: true })
} else {
setTouched({ ...touched, title: false })
}
}
}
if (openTugas) return <ViewDateEndTask onClose={(val) => { setOpenTugas(false) }} onSet={(val) => { if (openTugas) return <ViewDateEndTask onClose={(val) => { setOpenTugas(false) }} onSet={(val) => {
setDataTask([...dataTask, val]) setDataTask([...dataTask, val])
setOpenTugas(false) setOpenTugas(false)
@@ -127,11 +162,7 @@ export default function CreateTask() {
size="md" size="md"
label="Judul Tugas" label="Judul Tugas"
value={title} value={title}
onChange={(e) => { onChange={(e) => { onValidation('title', e.target.value) }}
setTitle(e.target.value)
setTouched({ ...touched, title: false })
}}
onBlur={() => setTouched({ ...touched, title: true })}
required required
error={ error={
touched.title && ( touched.title && (
@@ -291,15 +322,7 @@ export default function CreateTask() {
bg={tema.get().utama} bg={tema.get().utama}
size="lg" radius={30} size="lg" radius={30}
fullWidth fullWidth
onClick={() => { onClick={() => { onCheck() }}>
if (
title !== ""
) {
setOpenModal(true)
} else {
toast.error("Semua form harus diisi")
}
}}>
Simpan Simpan
</Button> </Button>
</Box> </Box>

View File

@@ -1,28 +1,15 @@
"use client"; "use client";
import { LayoutNavbarNew, TEMA } from "@/module/_global"; import { LayoutNavbarNew, TEMA } from "@/module/_global";
import {
Avatar,
Box,
Button,
Flex,
Group,
Input,
rem,
SimpleGrid,
Skeleton,
Stack,
Text,
TextInput,
} from "@mantine/core";
import React, { useState } from "react";
import { DatePicker } from "@mantine/dates";
import { useParams, useRouter } from "next/navigation";
import toast from "react-hot-toast";
import moment from "moment";
import { funEditDetailTask, funGetDetailTask } from "../lib/api_task";
import { useShallowEffect } from "@mantine/hooks";
import LayoutModal from "@/module/_global/layout/layout_modal"; import LayoutModal from "@/module/_global/layout/layout_modal";
import { useHookstate } from "@hookstate/core"; import { useHookstate } from "@hookstate/core";
import { Box, Button, Group, rem, SimpleGrid, Skeleton, Stack, Text, TextInput } from "@mantine/core";
import { DatePicker } from "@mantine/dates";
import { useShallowEffect } from "@mantine/hooks";
import moment from "moment";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-hot-toast";
import { funEditDetailTask, funGetDetailTask } from "../lib/api_task";
export default function EditDetailTask() { export default function EditDetailTask() {
@@ -185,10 +172,10 @@ export default function EditDetailTask() {
touched.title && touched.title &&
(title == "" ? "Error! harus memasukkan Judul Tahapan" : "" (title == "" ? "Error! harus memasukkan Judul Tahapan" : ""
) )
} }
onChange={(e) => { onChange={(e) => {
onValidation('title', e.target.value) onValidation('title', e.target.value)
}} }}
/> />
} }
</Stack> </Stack>

View File

@@ -1,22 +1,13 @@
"use client"; "use client";
import { LayoutNavbarNew, TEMA } from "@/module/_global"; import { LayoutNavbarNew, TEMA } from "@/module/_global";
import {
Box,
Button,
Input,
rem,
Skeleton,
Stack,
Textarea,
TextInput,
} from "@mantine/core";
import React, { useState } from "react";
import { useParams, useRouter } from "next/navigation";
import toast from "react-hot-toast";
import LayoutModal from "@/module/_global/layout/layout_modal"; import LayoutModal from "@/module/_global/layout/layout_modal";
import { funEditTask, funGetTaskDivisionById } from "../lib/api_task";
import { useShallowEffect } from "@mantine/hooks";
import { useHookstate } from "@hookstate/core"; import { useHookstate } from "@hookstate/core";
import { Box, Button, rem, Skeleton, Stack, TextInput } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-hot-toast";
import { funEditTask, funGetTaskDivisionById } from "../lib/api_task";
export default function EditTask() { export default function EditTask() {
@@ -31,12 +22,22 @@ export default function EditTask() {
}); });
function onVerification() { function onVerification() {
if (title == "") if (Object.values(touched).some((v) => v == true))
return toast.error("Error! harus memasukkan judul tugas") return false
setOpenModal(true) setOpenModal(true)
} }
function onValidation(kategori: string, val: string) {
if (kategori == 'title') {
setTitle(val)
if (val === "") {
setTouched({ ...touched, title: true })
} else {
setTouched({ ...touched, title: false })
}
}
}
async function onSubmit() { async function onSubmit() {
try { try {
const res = await funEditTask(param.detail, { title }) const res = await funEditTask(param.detail, { title })
@@ -96,16 +97,12 @@ export default function EditTask() {
label="Judul Tugas" label="Judul Tugas"
size="md" size="md"
value={title} value={title}
onChange={(e) => { onChange={(e) => { onValidation('title', e.target.value)}}
setTitle(e.target.value)
setTouched({ ...touched, title: false })
}}
error={ error={
touched.title && ( touched.title && (
title == "" ? "Error! harus memasukkan judul tugas" : null title == "" ? "Error! harus memasukkan judul tugas" : null
) )
} }
onBlur={() => setTouched({ ...touched, title: true })}
/> />
} }
</Stack> </Stack>