upd: fix: jumlah dokumen grafik pada home
This commit is contained in:
@@ -20,6 +20,7 @@ export default function ChartDokumenHome({ refreshing }: { refreshing: boolean }
|
|||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const [data, setData] = useState<Props>([])
|
const [data, setData] = useState<Props>([])
|
||||||
const [maxValue, setMaxValue] = useState(5)
|
const [maxValue, setMaxValue] = useState(5)
|
||||||
|
const [chartKey, setChartKey] = useState(0)
|
||||||
const barData = [
|
const barData = [
|
||||||
{ value: 23, label: 'Gambar', frontColor: '#fac858' },
|
{ value: 23, label: 'Gambar', frontColor: '#fac858' },
|
||||||
{ value: 12, label: 'Dokumen', frontColor: '#92cc76' },
|
{ value: 12, label: 'Dokumen', frontColor: '#92cc76' },
|
||||||
@@ -32,8 +33,8 @@ export default function ChartDokumenHome({ refreshing }: { refreshing: boolean }
|
|||||||
setLoading(loading)
|
setLoading(loading)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetDataHome({ cat: "dokumen", user: hasil })
|
const response = await apiGetDataHome({ cat: "dokumen", user: hasil })
|
||||||
const maxValue = response.data.reduce((max: number, obj: { value: number; }) => Math.max(max, obj.value), -Infinity);
|
const maxVal = response.data.reduce((max: number, obj: { value: number; }) => Math.max(max, Number(obj.value)), 0);
|
||||||
const roundUp = Math.ceil(maxValue / 10) * 10
|
const roundUp = maxVal > 0 ? Math.ceil(maxVal / 10) * 10 : 10;
|
||||||
setMaxValue(roundUp)
|
setMaxValue(roundUp)
|
||||||
const convertedArray = response.data.map((item: { color: any; label: any; value: any; }) => ({
|
const convertedArray = response.data.map((item: { color: any; label: any; value: any; }) => ({
|
||||||
frontColor: item.color,
|
frontColor: item.color,
|
||||||
@@ -41,6 +42,7 @@ export default function ChartDokumenHome({ refreshing }: { refreshing: boolean }
|
|||||||
value: Number(item.value)
|
value: Number(item.value)
|
||||||
}));
|
}));
|
||||||
setData(convertedArray)
|
setData(convertedArray)
|
||||||
|
setChartKey((prev: number) => prev + 1)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -49,8 +51,9 @@ export default function ChartDokumenHome({ refreshing }: { refreshing: boolean }
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (refreshing)
|
if (refreshing) {
|
||||||
handleData(false)
|
handleData(false)
|
||||||
|
}
|
||||||
}, [refreshing]);
|
}, [refreshing]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -64,6 +67,7 @@ export default function ChartDokumenHome({ refreshing }: { refreshing: boolean }
|
|||||||
loading ? <Skeleton width={100} height={200} borderRadius={10} widthType="percent" />
|
loading ? <Skeleton width={100} height={200} borderRadius={10} widthType="percent" />
|
||||||
:
|
:
|
||||||
<BarChart
|
<BarChart
|
||||||
|
key={chartKey}
|
||||||
showFractionalValues={false}
|
showFractionalValues={false}
|
||||||
showYAxisIndices
|
showYAxisIndices
|
||||||
noOfSections={4}
|
noOfSections={4}
|
||||||
|
|||||||
Reference in New Issue
Block a user