Commit 23f63534 authored by Hardiansyah's avatar Hardiansyah

reuse component

parent 2dc61b4e
import React, { Component } from 'react' import React, { Component } from 'react'
import { Paper, } from '@material-ui/core'; import { Paper, } from '@material-ui/core';
import AlertSnackbar from '../../library/AlertSnackbar' import AlertSnackbar from '../../library/AlertSnackbar'
import Header from '../../library/Header';
import SectionHeader from '../../library/SectionHeader'; import SectionHeader from '../../library/SectionHeader';
import AutocompleteField from '../../library/AutocompleteField'; import AutocompleteField from '../../library/AutocompleteField';
import CustomButton from '../../library/CustomButton'; import CustomButton from '../../library/CustomButton';
...@@ -11,6 +10,7 @@ import DDLMonth from '../../library/Dropdown/DDLMonth'; ...@@ -11,6 +10,7 @@ import DDLMonth from '../../library/Dropdown/DDLMonth';
import DDLCompany from '../../library/Dropdown/DDLCompany'; import DDLCompany from '../../library/Dropdown/DDLCompany';
import ContentContainer from '../../library/ContentContainer'; import ContentContainer from '../../library/ContentContainer';
import Constant from '../../library/Constant'; import Constant from '../../library/Constant';
import { downloadFileBlob } from '../../library/Utils';
class ReportHistorical extends Component { class ReportHistorical extends Component {
constructor(props) { constructor(props) {
...@@ -115,14 +115,7 @@ class ReportHistorical extends Component { ...@@ -115,14 +115,7 @@ class ReportHistorical extends Component {
const blob = res.data const blob = res.data
if (blob && blob.size > 0) { if (blob && blob.size > 0) {
const url = window.URL.createObjectURL(blob) downloadFileBlob('Historical.xlsx', blob)
const a = document.createElement('a')
a.href = url
a.download = 'Historical.xlsx'
document.body.appendChild(a)
a.click()
a.remove()
window.URL.revokeObjectURL(url)
} }
this.showAlert('Download Berhasil', 'success'); this.showAlert('Download Berhasil', 'success');
...@@ -139,10 +132,7 @@ class ReportHistorical extends Component { ...@@ -139,10 +132,7 @@ class ReportHistorical extends Component {
const contentStyle = { display: 'flex', marginTop: 10, gap: '20px' }; const contentStyle = { display: 'flex', marginTop: 10, gap: '20px' };
return ( return (
<ContentContainer isLoading={isLoading}> <ContentContainer isLoading={isLoading} title="Report Historical">
<Header
title="Report Historical"
/>
<div style={{ padding: 20 }}> <div style={{ padding: 20 }}>
<Paper style={{ paddingTop: 10, paddingBottom: 20 }}> <Paper style={{ paddingTop: 10, paddingBottom: 20 }}>
<SectionHeader <SectionHeader
...@@ -155,6 +145,7 @@ class ReportHistorical extends Component { ...@@ -155,6 +145,7 @@ class ReportHistorical extends Component {
value={data?.report_id} value={data?.report_id}
onChange={(event, newValue) => this.handleChangeDropdown(newValue, 'report_id')} onChange={(event, newValue) => this.handleChangeDropdown(newValue, 'report_id')}
label="Report Type" label="Report Type"
isLoading={isLoading}
/> />
<AutocompleteField <AutocompleteField
options={listPeriodType} options={listPeriodType}
......
...@@ -59,7 +59,7 @@ class AlertSnackbar extends Component { ...@@ -59,7 +59,7 @@ class AlertSnackbar extends Component {
children, children,
// Props untuk Snackbar // Props untuk Snackbar
autoHideDuration = 1500, autoHideDuration = 2000,
anchorOrigin = { vertical: 'bottom', horizontal: 'center' }, anchorOrigin = { vertical: 'bottom', horizontal: 'center' },
// Props untuk Alert // Props untuk Alert
......
...@@ -3,6 +3,7 @@ import { TextField, Checkbox } from '@material-ui/core'; ...@@ -3,6 +3,7 @@ import { TextField, Checkbox } from '@material-ui/core';
import { Autocomplete } from '@material-ui/lab'; import { Autocomplete } from '@material-ui/lab';
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';
import CheckBoxIcon from '@material-ui/icons/CheckBox'; import CheckBoxIcon from '@material-ui/icons/CheckBox';
import CircularProgress from '@material-ui/core/CircularProgress';
const icon = <CheckBoxOutlineBlankIcon fontSize="small" />; const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
const checkedIcon = <CheckBoxIcon fontSize="small" />; const checkedIcon = <CheckBoxIcon fontSize="small" />;
...@@ -25,6 +26,7 @@ const AutocompleteField = ({ ...@@ -25,6 +26,7 @@ const AutocompleteField = ({
noOptionsText = "No options available", noOptionsText = "No options available",
multiple = false, multiple = false,
showCheckbox = false, showCheckbox = false,
isLoading = false,
...props ...props
}) => { }) => {
const defaultRenderInput = (params) => ( const defaultRenderInput = (params) => (
...@@ -38,6 +40,17 @@ const AutocompleteField = ({ ...@@ -38,6 +40,17 @@ const AutocompleteField = ({
error={error} error={error}
helperText={helperText} helperText={helperText}
fullWidth fullWidth
InputProps={{
...params.InputProps,
endAdornment: (
<>
{isLoading ? (
<CircularProgress color="inherit" size={20} />
) : null}
{params.InputProps.endAdornment}
</>
),
}}
/> />
); );
...@@ -89,6 +102,7 @@ const AutocompleteField = ({ ...@@ -89,6 +102,7 @@ const AutocompleteField = ({
return option.id === value.id; return option.id === value.id;
}} }}
renderOption={showCheckbox && multiple ? renderOptionWithCheckbox : undefined} renderOption={showCheckbox && multiple ? renderOptionWithCheckbox : undefined}
loadingText="Loading..."
{...props} {...props}
/> />
); );
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import OverlayLoader from './OverlayLoader'; import OverlayLoader from './OverlayLoader';
import Header from './Header';
class ContentContainer extends Component { class ContentContainer extends Component {
render() { render() {
...@@ -11,6 +12,7 @@ class ContentContainer extends Component { ...@@ -11,6 +12,7 @@ class ContentContainer extends Component {
padding = 0, padding = 0,
style = {}, style = {},
loaderProps = {}, loaderProps = {},
title = '',
...restProps ...restProps
} = this.props; } = this.props;
...@@ -27,6 +29,9 @@ class ContentContainer extends Component { ...@@ -27,6 +29,9 @@ class ContentContainer extends Component {
{isLoading && ( {isLoading && (
<OverlayLoader isLoading={isLoading} {...loaderProps} /> <OverlayLoader isLoading={isLoading} {...loaderProps} />
)} )}
<Header
title={title}
/>
{children} {children}
</div> </div>
); );
......
...@@ -11,6 +11,7 @@ class DDLCompany extends Component { ...@@ -11,6 +11,7 @@ class DDLCompany extends Component {
? (props.value || []) ? (props.value || [])
: (props.value || null), : (props.value || null),
companies: [], companies: [],
isLoading: false,
}; };
} }
...@@ -30,8 +31,13 @@ class DDLCompany extends Component { ...@@ -30,8 +31,13 @@ class DDLCompany extends Component {
} }
} }
setLoading = (isLoading) => {
this.setState({ isLoading });
}
getCompanyActive = async () => { getCompanyActive = async () => {
try { try {
this.setLoading(true);
const response = await api.create().getPerusahaanActive(); const response = await api.create().getPerusahaanActive();
const data = response?.data?.data || []; const data = response?.data?.data || [];
...@@ -44,6 +50,8 @@ class DDLCompany extends Component { ...@@ -44,6 +50,8 @@ class DDLCompany extends Component {
} catch (err) { } catch (err) {
console.error('Failed to load companies', err); console.error('Failed to load companies', err);
this.setState({ companies: [] }); this.setState({ companies: [] });
} finally {
this.setLoading(false);
} }
}; };
...@@ -117,7 +125,7 @@ class DDLCompany extends Component { ...@@ -117,7 +125,7 @@ class DDLCompany extends Component {
multiple, multiple,
} = this.props; } = this.props;
const { selectedValue, companies } = this.state; const { selectedValue, companies, isLoading } = this.state;
return ( return (
<AutocompleteField <AutocompleteField
...@@ -134,7 +142,7 @@ class DDLCompany extends Component { ...@@ -134,7 +142,7 @@ class DDLCompany extends Component {
margin={margin} margin={margin}
multiple={multiple} multiple={multiple}
showCheckbox={multiple} showCheckbox={multiple}
noOptionsText="No companies available" isLoading={isLoading}
/> />
); );
} }
......
...@@ -180,7 +180,6 @@ class DDLYear extends Component { ...@@ -180,7 +180,6 @@ class DDLYear extends Component {
helperText={helperText} helperText={helperText}
style={style} style={style}
margin={margin} margin={margin}
noOptionsText="No years available"
/> />
); );
} }
......
export function titleCase(text) { export function titleCase(text) {
var value = String(text).replace(/\./g, ' ') var value = String(text).replace(/\./g, ' ')
.replace(/\s/g, ' ') .replace(/\s/g, ' ')
.replace(/^(.)/, function($1) { return $1.toUpperCase(); }) .replace(/^(.)/, function ($1) { return $1.toUpperCase(); })
// .replace(/\s(.)/g, function($1) { return $1.toUpperCase(); }) // .replace(/\s(.)/g, function($1) { return $1.toUpperCase(); })
return value return value
...@@ -13,6 +13,17 @@ export function roundMath(number, decimalPlaces) { ...@@ -13,6 +13,17 @@ export function roundMath(number, decimalPlaces) {
} }
export function fixNumber(num, decimalCount = 2) { export function fixNumber(num, decimalCount = 2) {
const output = Math.round((num + Number.EPSILON) * (Math.pow(10,decimalCount))) / (Math.pow(10,decimalCount)) const output = Math.round((num + Number.EPSILON) * (Math.pow(10, decimalCount))) / (Math.pow(10, decimalCount))
return output return output
} }
export function downloadFileBlob(fileName, blobData) {
const url = window.URL.createObjectURL(blobData)
const a = document.createElement('a')
a.href = url
a.download = fileName
document.body.appendChild(a)
a.click()
a.remove()
window.URL.revokeObjectURL(url)
}
\ No newline at end of file
Markdown is supported
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