Fakultas Ilmu Komputer UI

Commit 1378d845 authored by Lia Yuliana's avatar Lia Yuliana
Browse files

[GREEN] connect formiumk to backend

parent 6df1ec8a
Pipeline #72907 passed with stages
in 12 minutes and 4 seconds
......@@ -5,9 +5,14 @@ import FormIUMK2 from '../components/FormIUMK/FormIUMK2'
import FormIUMK3 from '../components/FormIUMK/FormIUMK3'
import Stepper from '../components/Stepper/Stepper'
import {useSelector} from 'react-redux'
import {getEmail, isLoggedIn} from '../store/auth/authSlice'
import {getEmail, isLoggedIn, getToken} from '../store/auth/authSlice'
import {useState} from 'react'
import {useForm} from 'react-hook-form'
import axios from 'axios'
import BASE_URL from '../api/config'
import {navigate} from '@reach/router'
import toast, {Toaster} from 'react-hot-toast'
const FormIUMK = () => {
const {register, handleSubmit, errors, setValue} = useForm({
......@@ -16,6 +21,7 @@ const FormIUMK = () => {
})
const name = useSelector(getEmail)
const loggedIn = useSelector(isLoggedIn)
const token = useSelector(getToken)
const [pageNumber, setPageNumber] = useState(1)
const [data, setData] = useState({})
const [employeeData, setEmployeeData] = useState(null)
......@@ -28,6 +34,43 @@ const FormIUMK = () => {
} else {
setData({...data, ...input, ...{karyawan: employeeData}})
}
} else {
axios
.post(
`${BASE_URL.API_BASE_URL}/api/v1/iumk/`,
{
nama_usaha: data.nama,
alamat: data.alamat,
barang_jasa: data.barangJasa,
status_entitas: data.status,
jumlah_karyawan: data.karyawan,
kode_kbli: data.kbli,
catatan: data.catatan,
},
{
headers: {
Authorization: `Token ${token}`,
},
},
)
.then(() => {
navigate('/', {
state: {
message: 'Pengajuan Izin UMK berhasil terkirim',
showToast: true,
},
replace: false,
})
})
.catch((error) => {
if (error.response.data.non_field_errors) {
toast.error(
<span data-testid="toast-error">
{error.response.data.non_field_errors}
</span>,
)
}
})
}
}
......@@ -68,9 +111,16 @@ const FormIUMK = () => {
/>
)}
{pageNumber == 3 && <FormIUMK3 data={data} />}
{pageNumber == 3 && (
<FormIUMK3
data={data}
onSubmit={onSubmit}
handleSubmit={handleSubmit}
/>
)}
</div>
</div>
<Toaster />
</div>
)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment