feat :update module
This commit is contained in:
1
src/module/_global/bin/val_global.ts
Normal file
1
src/module/_global/bin/val_global.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const pwd_key_config = "fchgvjknlmdfnbvghhujlaknsdvjbhknlkmsdbdyu567t8y9u30r4587638y9uipkoeghjvuyi89ipkoefmnrjbhtiu4or9ipkoemnjfbhjiuoijdklnjhbviufojkejnshbiuojijknehgruyu"
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import prisma from "./bin/prisma";
|
||||||
|
import { pwd_key_config } from "./bin/val_global";
|
||||||
import { WARNA } from "./fun/WARNA";
|
import { WARNA } from "./fun/WARNA";
|
||||||
import LayoutDrawer from "./layout/layout_drawer";
|
import LayoutDrawer from "./layout/layout_drawer";
|
||||||
import LayoutIconBack from "./layout/layout_icon_back";
|
import LayoutIconBack from "./layout/layout_icon_back";
|
||||||
@@ -7,11 +9,13 @@ import LayoutNavbarHome from "./layout/layout_navbar_home";
|
|||||||
import LayoutNavbarNew from "./layout/layout_navbar_new";
|
import LayoutNavbarNew from "./layout/layout_navbar_new";
|
||||||
import ViewFilter from "./view/view_filter";
|
import ViewFilter from "./view/view_filter";
|
||||||
|
|
||||||
export { WARNA }
|
export { WARNA };
|
||||||
export { LayoutLogin }
|
export { LayoutLogin };
|
||||||
export { LayoutNavbarHome }
|
export { LayoutNavbarHome };
|
||||||
export { LayoutIconBack }
|
export { LayoutIconBack };
|
||||||
export { LoadingPage }
|
export { LoadingPage };
|
||||||
export { LayoutDrawer }
|
export { LayoutDrawer };
|
||||||
export { LayoutNavbarNew }
|
export { LayoutNavbarNew };
|
||||||
export { ViewFilter }
|
export { ViewFilter };
|
||||||
|
export { prisma };
|
||||||
|
export { pwd_key_config };
|
||||||
|
|||||||
@@ -12,24 +12,68 @@ import {
|
|||||||
Title,
|
Title,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import ViewVerification from "../../varification/view/view_verification";
|
||||||
|
import { useFocusTrap } from "@mantine/hooks";
|
||||||
|
|
||||||
function ViewLogin() {
|
function ViewLogin() {
|
||||||
|
const focusTrapRef = useFocusTrap()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const textInfo =
|
const textInfo =
|
||||||
"Kami akan mengirim kode verifikasi melalui WhatsApp, guna mengonfirmasikan nomor Anda.";
|
"Kami akan mengirim kode verifikasi melalui WhatsApp, guna mengonfirmasikan nomor Anda.";
|
||||||
|
|
||||||
function onMasuk() {
|
const [isPhone, setPhone] = useState("")
|
||||||
// router.push("/verification")
|
const [isOTP, setOTP] = useState<any>(null)
|
||||||
window.location.href = "/verification"
|
const [isValPhone, setValPhone] = useState<any>(null)
|
||||||
|
const [isUser, setUser] = useState<any>(null)
|
||||||
|
const [isVerif, setVerif] = useState(false)
|
||||||
|
const [isLoading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
async function onLogin() {
|
||||||
|
if (isPhone == "")
|
||||||
|
return toast.error('Please fill in completely')
|
||||||
|
const cek = await fetch('/api/auth/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ phone: isPhone })
|
||||||
|
})
|
||||||
|
const json = await cek.json()
|
||||||
|
console.log(json)
|
||||||
|
|
||||||
|
const code = Math.floor(Math.random() * 1000) + 1000
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
const res = await fetch(`https://wa.wibudev.com/code?nom=${json.phone}&text=${code}`).then(
|
||||||
|
async (res) => {
|
||||||
|
if (res.status == 200) {
|
||||||
|
setValPhone(json.phone)
|
||||||
|
setOTP(code)
|
||||||
|
setUser(json.id)
|
||||||
|
setVerif(true)
|
||||||
|
setLoading(false)
|
||||||
|
toast.success('OTP sent successfully')
|
||||||
|
} else {
|
||||||
|
toast.error('OTP not sent')
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
console.log("code", code)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isVerif) return <ViewVerification otp={isOTP} phone={isValPhone} user={isUser} />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box p={10}>
|
<Box p={10}>
|
||||||
<LayoutLogin>
|
<LayoutLogin>
|
||||||
<Stack pt={30}>
|
<Stack pt={30}>
|
||||||
<Box p={10}>
|
<Box p={10} ref={focusTrapRef}>
|
||||||
<TextInput
|
<TextInput
|
||||||
styles={{
|
styles={{
|
||||||
input: {
|
input: {
|
||||||
@@ -43,6 +87,7 @@ function ViewLogin() {
|
|||||||
radius={30}
|
radius={30}
|
||||||
leftSection={<Text>+62</Text>}
|
leftSection={<Text>+62</Text>}
|
||||||
placeholder="XXX XXX XXX"
|
placeholder="XXX XXX XXX"
|
||||||
|
onChange={(val) => { setPhone(val.target.value) }}
|
||||||
/>
|
/>
|
||||||
<Text fz={10} mt={10} c={WARNA.biruTua}>
|
<Text fz={10} mt={10} c={WARNA.biruTua}>
|
||||||
{textInfo}
|
{textInfo}
|
||||||
@@ -62,7 +107,10 @@ function ViewLogin() {
|
|||||||
size="md"
|
size="md"
|
||||||
radius={30}
|
radius={30}
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={onMasuk}
|
loading={isLoading}
|
||||||
|
onClick={() => {
|
||||||
|
onLogin()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
MASUK
|
MASUK
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,16 +1,54 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { LayoutLogin, WARNA } from "@/module/_global";
|
import { LayoutLogin, WARNA } from "@/module/_global";
|
||||||
import { Box, Button, PinInput, Stack, Text, Title } from "@mantine/core";
|
import { IVerification } from "@/types";
|
||||||
|
import { Anchor, Box, Button, Group, PinInput, Stack, Text, Title } from "@mantine/core";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
export default function ViewVerification() {
|
export default function ViewVerification({ phone, otp, user }: IVerification) {
|
||||||
const router = useRouter();
|
const router = useRouter()
|
||||||
|
const [isOTP, setOTP] = useState(otp)
|
||||||
|
const [inputOTP, setInputOTP] = useState<any>()
|
||||||
|
const [isLoading, setLoading] = useState(false)
|
||||||
|
|
||||||
function onNext() {
|
async function onResend() {
|
||||||
// router.push("/welcome");
|
const code = Math.floor(Math.random() * 1000) + 1000
|
||||||
window.location.href = "/welcome"
|
|
||||||
|
const res = await fetch(`https://wa.wibudev.com/code?nom=${phone}&text=${code}`)
|
||||||
|
.then(
|
||||||
|
async (res) => {
|
||||||
|
if (res.status == 200) {
|
||||||
|
toast.success('Verification code has been sent')
|
||||||
|
setOTP(code)
|
||||||
|
} else {
|
||||||
|
toast.error('Error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getVerification() {
|
||||||
|
setLoading(true)
|
||||||
|
if (isOTP == inputOTP) {
|
||||||
|
setLoading(false)
|
||||||
|
const res = await fetch('/api/auth/set-cookies', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ user: user })
|
||||||
|
})
|
||||||
|
router.push('/welcome')
|
||||||
|
toast.success("Verification code is correct")
|
||||||
|
setLoading(false)
|
||||||
|
} else {
|
||||||
|
toast.error("Verification code is incorrect")
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box p={10}>
|
<Box p={10}>
|
||||||
@@ -24,7 +62,7 @@ export default function ViewVerification() {
|
|||||||
Masukkan kode yang kami kirimkan melalui WhatsApp
|
Masukkan kode yang kami kirimkan melalui WhatsApp
|
||||||
</Text>
|
</Text>
|
||||||
<Text fz={12} c={WARNA.biruTua} fw={"bold"}>
|
<Text fz={12} c={WARNA.biruTua} fw={"bold"}>
|
||||||
+6287701790942
|
{phone}
|
||||||
</Text>
|
</Text>
|
||||||
<Box pt={30}>
|
<Box pt={30}>
|
||||||
<PinInput
|
<PinInput
|
||||||
@@ -39,6 +77,9 @@ export default function ViewVerification() {
|
|||||||
borderColor: WARNA.biruTua,
|
borderColor: WARNA.biruTua,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
onChange={(val) => {
|
||||||
|
setInputOTP(val)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box mt={40}>
|
<Box mt={40}>
|
||||||
@@ -48,11 +89,22 @@ export default function ViewVerification() {
|
|||||||
size="md"
|
size="md"
|
||||||
radius={30}
|
radius={30}
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={onNext}
|
onClick={() => { getVerification() }}
|
||||||
>
|
>
|
||||||
Lanjut
|
Lanjut
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
<Group justify="center" >
|
||||||
|
<Text fz={12} c={WARNA.biruTua}>
|
||||||
|
Didnt receive a code ? {""}
|
||||||
|
<Anchor c={WARNA.biruTua}
|
||||||
|
fz={12}
|
||||||
|
onClick={() => { onResend() }}
|
||||||
|
>
|
||||||
|
Resend
|
||||||
|
</Anchor>
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
</LayoutLogin>
|
</LayoutLogin>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use client"
|
||||||
import { LayoutIconBack, LayoutNavbarHome, WARNA } from "@/module/_global";
|
import { LayoutIconBack, LayoutNavbarHome, WARNA } from "@/module/_global";
|
||||||
import { ActionIcon, Anchor, Box, Button, Flex, Group, Stack, Text } from "@mantine/core";
|
import { ActionIcon, Anchor, Box, Button, Flex, Group, Stack, Text } from "@mantine/core";
|
||||||
import { BsInfo } from "react-icons/bs";
|
import { BsInfo } from "react-icons/bs";
|
||||||
@@ -7,16 +8,34 @@ import { FaSquarePhone } from "react-icons/fa6";
|
|||||||
import { MdEmail } from "react-icons/md";
|
import { MdEmail } from "react-icons/md";
|
||||||
import { InfoTitleProfile } from "../component/ui/ui_profile";
|
import { InfoTitleProfile } from "../component/ui/ui_profile";
|
||||||
import { IoMaleFemale } from "react-icons/io5";
|
import { IoMaleFemale } from "react-icons/io5";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { LuLogOut } from "react-icons/lu";
|
||||||
|
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function ViewProfile() {
|
export default function ViewProfile() {
|
||||||
|
const [openModal, setOpenModal] = useState(false);
|
||||||
|
|
||||||
|
async function onLogout() {
|
||||||
|
try {
|
||||||
|
await fetch('/api/auth/logout', {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
toast.success('Logout Success')
|
||||||
|
window.location.href = '/';
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LayoutNavbarHome>
|
<LayoutNavbarHome>
|
||||||
<Group justify="space-between">
|
<Group justify="space-between">
|
||||||
<LayoutIconBack />
|
<LayoutIconBack />
|
||||||
{/* <ActionIcon variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Info">
|
|
||||||
<BsInfo size={20} color='white' />
|
<ActionIcon onClick={() => { setOpenModal(true) }} variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Info">
|
||||||
</ActionIcon> */}
|
<LuLogOut size={20} color='white' />
|
||||||
|
</ActionIcon>
|
||||||
</Group>
|
</Group>
|
||||||
<Stack
|
<Stack
|
||||||
align="center"
|
align="center"
|
||||||
@@ -60,6 +79,10 @@ export default function ViewProfile() {
|
|||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
<LayoutModal opened={openModal} onClose={() => setOpenModal(false)}
|
||||||
|
description="Apakah Anda yakin ingin Keluar?"
|
||||||
|
onYes={() => onLogout()} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user