-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import Swal from 'sweetalert2'; | ||
import { CCard, CCardBody } from '@coreui/react' | ||
import axiosConfig from "../../../api/axios"; | ||
import Form from './components/Form'; | ||
import Header from '../../.components/CardHeader'; | ||
import Load from '../../.components/Loading'; | ||
|
||
|
||
const Add = () => { | ||
const [value, setValue] = useState(""); | ||
const [load, setLoad] = useState(false); | ||
const history = useHistory(); | ||
let data = { | ||
name: "", | ||
code_name: "" , | ||
} | ||
|
||
useEffect(() => { | ||
|
||
}, []); | ||
|
||
const handleForm = (value) => { | ||
setValue(value); | ||
} | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
setLoad(true); | ||
const token = JSON.parse(sessionStorage.getItem("token")); | ||
let config = { | ||
headers : { authorization: `Bearer ${token}` } | ||
}; | ||
try { | ||
await axiosConfig.post('/manufactures', value, config) | ||
.then(res => { | ||
const data = res.data; | ||
if (data.status === 201){ | ||
setLoad(false); | ||
Swal.fire({ | ||
title: 'Sukses', | ||
text: 'Data berhasil ditambahkan!', | ||
icon: 'success', | ||
timer: 1500, | ||
}); | ||
history.push('/produk/manufaktur'); | ||
} else if (data.status === 500){ | ||
setLoad(false); | ||
Swal.fire({ | ||
title: 'Gagal', | ||
text: 'Periksa kembali kolom form !', | ||
icon: 'warning', | ||
timer: 1500, | ||
}); | ||
} else if (data.status === 404){ | ||
setLoad(false); | ||
Swal.fire({ | ||
title: 'Gagal', | ||
text: 'Error', | ||
icon: 'error', | ||
timer: 1500, | ||
}); | ||
} | ||
}) | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
|
||
return ( | ||
<CCard> | ||
<Header title="Menambahkan Manufaktur Produk" type="kembali" link="/produk/manufaktur" /> | ||
<CCardBody> | ||
{ (load === true) ? <Load /> : | ||
// <CForm action="" method="post" encType="multipart/form-data" className="form-horizontal" onSubmit={e => {handleSubmit(e)}}> | ||
<Form value={handleForm} temp={data} submit={handleSubmit}/> | ||
// {/* <CButton type="submit" size="sm" color="primary"><CIcon name="cil-scrubber" /> Submit</CButton> | ||
// </CForm> */} | ||
} | ||
</CCardBody> | ||
</CCard> | ||
) | ||
} | ||
|
||
export default Add; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import Swal from 'sweetalert2'; | ||
import { CCard, CCardBody, CForm, CButton } from '@coreui/react' | ||
import CIcon from '@coreui/icons-react' | ||
import axiosConfig from "../../../api/axios"; | ||
import Form from './components/Form'; | ||
import Header from '../../.components/CardHeader'; | ||
import Load from '../../.components/Loading'; | ||
|
||
|
||
const Edit = ({match}) => { | ||
|
||
const id = match.params.id; | ||
const [data, setData] = useState(); | ||
const [value, setValue] = useState(""); | ||
const [load, setLoad] = useState(true); | ||
const history = useHistory(); | ||
|
||
|
||
useEffect(() => { | ||
const getType = async () => { | ||
try { | ||
await axiosConfig.get(`/manufactures/${id}`).then(res => { | ||
setData(res.data); | ||
setLoad(false) | ||
}) | ||
} catch(error) { | ||
|
||
} | ||
} | ||
getType() | ||
}, [setData]); | ||
|
||
const handleForm = (value) => { | ||
setValue(value); | ||
} | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
setLoad(true); | ||
// const fd = new FormData(); | ||
// fd.append('name', value.model_produk); | ||
// fd.append('code_name', value.code_name); | ||
// fd.append('satuan', value.satuan); | ||
// fd.append('code_satuan', value.code_satuan); | ||
|
||
|
||
const token = JSON.parse(sessionStorage.getItem("token")); | ||
let config = { | ||
headers : { authorization: `Bearer ${token}` } | ||
}; | ||
try { | ||
await axiosConfig.patch(`/manufactures/${id}`, value, config) | ||
.then(res => { | ||
const data = res.data; | ||
if (data.status === 201){ | ||
setLoad(false); | ||
Swal.fire({ | ||
title: 'Sukses', | ||
text: 'Data berhasil diubah!', | ||
icon: 'success', | ||
timer: 1500, | ||
}); | ||
history.push('/produk/manufaktur'); | ||
} else if (data.status === 500){ | ||
setLoad(false); | ||
Swal.fire({ | ||
title: 'Gagal', | ||
text: 'Periksa kembali kolom form !', | ||
icon: 'warning', | ||
timer: 1500, | ||
}); | ||
} else if (data.status === 404){ | ||
setLoad(false); | ||
Swal.fire({ | ||
title: 'Gagal', | ||
text: 'Error', | ||
icon: 'error', | ||
timer: 1500, | ||
}); | ||
} | ||
}) | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
|
||
return ( | ||
<CCard> | ||
<Header title="Ubah Tipe Produk" type="kembali" link="/produk/manufaktur" /> | ||
<CCardBody> | ||
{ (load === true) ? <Load /> : | ||
<Form value={handleForm} temp={data} submit={handleSubmit}/> | ||
} | ||
</CCardBody> | ||
</CCard> | ||
) | ||
} | ||
|
||
export default Edit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import axiosConfig from "../../../api/axios"; | ||
|
||
import { CCard, CCardBody } from '@coreui/react'; | ||
|
||
import Header from '../../.components/CardHeader'; | ||
|
||
import Loadwait from '../../.components/Loading'; | ||
|
||
|
||
const Type = ({match}) => { | ||
|
||
const id = match.params.id; | ||
const [isload, setIsload] = useState(true) | ||
const [ data, setData ] = useState([]); | ||
const token = JSON.parse(sessionStorage.getItem("token")); | ||
|
||
|
||
useEffect(() => { | ||
let headers = { | ||
authorization: `Bearer ${token}`, | ||
}; | ||
const getData = async () => { | ||
try { | ||
await axiosConfig.get(`/manufactures/${id}`, headers) | ||
.then(res => { | ||
setData(res.data); | ||
setIsload(false); | ||
}) | ||
} catch(error) { | ||
|
||
} | ||
} | ||
|
||
getData(); | ||
}, [setData]); | ||
|
||
const details = data ? Object.entries(data) : <></> | ||
|
||
return ( | ||
<> | ||
<CCard> | ||
<Header title="Detail Manufaktur Produk" type="kembali" link="/produk/manufaktur"/> | ||
{ (isload === true) ? <Loadwait /> : | ||
<CCardBody> | ||
<table> | ||
{ | ||
details.map(([key, value], index) => { | ||
return ( | ||
<tbody key={index.toString()}> | ||
<tr> | ||
<td>{`${key} :`}</td> | ||
<td><strong> {value}</strong></td> | ||
</tr> | ||
</tbody> | ||
) | ||
}) | ||
} | ||
</table> | ||
</CCardBody> | ||
} | ||
</CCard> | ||
</> | ||
) | ||
} | ||
|
||
export default Type; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { | ||
CCard, | ||
CCardBody, | ||
CCol, | ||
CRow, | ||
} from '@coreui/react'; | ||
import Table from './components/Table'; | ||
import axiosConfig from "../../../api/axios"; | ||
import CardHeader from '../../.components/CardHeader' | ||
import Swal from 'sweetalert2'; | ||
|
||
|
||
const Manufactures = () => { | ||
const [data, setData] = useState([]); | ||
const [load, setLoad] = useState(true); | ||
const token = JSON.parse(sessionStorage.getItem("token")); | ||
|
||
useEffect(() => { | ||
let headers = { | ||
authorization: `Bearer ${token}`, | ||
}; | ||
const getData = async () => { | ||
try { | ||
await axiosConfig.get('/manufactures', headers) | ||
.then((res) => { | ||
setData(res.data); | ||
setLoad(false); | ||
}) | ||
} catch(error) { | ||
|
||
} | ||
}; | ||
|
||
getData() | ||
}, [setData, setLoad]); | ||
|
||
const handleDelete = (id) => { | ||
let headers = { | ||
authorization: `Bearer ${token}`, | ||
}; | ||
const getAlert = () => { | ||
Swal.fire({ | ||
title: 'Yakin menghapus tipe produk ini ?', | ||
text: "Perubahan yang terjadi tidak dapat diubah kembali", | ||
icon: 'warning', | ||
showCancelButton: true, | ||
confirmButtonColor: '#3085d6', | ||
cancelButtonColor: '#d33', | ||
confirmButtonText: 'Ya, hapus tipe ini.' | ||
}).then((result) => { | ||
if (result.isConfirmed) { | ||
try { | ||
setLoad(true); | ||
axiosConfig.delete(`/manufactures/${id}`, headers) | ||
.then(res => { | ||
if (res.status === 200){ | ||
Swal.fire({ | ||
title: 'Sukses', | ||
text: 'Data berhasil dihapus!', | ||
icon: 'success', | ||
timer: 2000, | ||
}); | ||
let filtered = data.reduce((filter,data) => | ||
( data.id !== id && filter.push(data) ,filter ),[]); | ||
setData(filtered); | ||
setLoad(false) | ||
} | ||
}) | ||
} catch(error) { | ||
console.log(error) | ||
} | ||
} | ||
} | ||
) | ||
}; | ||
getAlert(); | ||
} | ||
|
||
|
||
return ( | ||
<CRow> | ||
<CCol lg={12}> | ||
<CCard> | ||
<CardHeader title="Daftar Manufaktur Produk" type="tambah" link="/produk/manufaktur/tambah"/> | ||
<CCardBody> | ||
<Table data={data} load={load} del={handleDelete}/> | ||
</CCardBody> | ||
</CCard> | ||
</CCol> | ||
</CRow> | ||
) | ||
} | ||
|
||
export default Manufactures; |
Oops, something went wrong.