upd: connected api monitoring
Deskripsi: - update version No Issues
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
import { VillageActivityLineChart, VillageComparisonBarChart } from '@/frontend/components/DashboardCharts'
|
||||
import { ErrorDataTable } from '@/frontend/components/ErrorDataTable'
|
||||
import { SummaryCard } from '@/frontend/components/SummaryCard'
|
||||
@@ -40,6 +42,13 @@ function AppOverviewPage() {
|
||||
const isDesaPlus = appId === 'desa-plus'
|
||||
const [versionModalOpened, { open: openVersionModal, close: closeVersionModal }] = useDisclosure(false)
|
||||
|
||||
// Form State
|
||||
const [latestVersion, setLatestVersion] = useState('')
|
||||
const [minVersion, setMinVersion] = useState('')
|
||||
const [messageUpdate, setMessageUpdate] = useState('')
|
||||
const [maintenance, setMaintenance] = useState(false)
|
||||
const [isSaving, setIsSaving] = useState(false)
|
||||
|
||||
// Data Fetching
|
||||
const { data: gridRes, isLoading: gridLoading, mutate: mutateGrid } = useSWR(isDesaPlus ? API_URLS.getGridOverview() : null, fetcher)
|
||||
const { data: dailyRes, isLoading: dailyLoading, mutate: mutateDaily } = useSWR(isDesaPlus ? API_URLS.getDailyActivity() : null, fetcher)
|
||||
@@ -49,31 +58,93 @@ function AppOverviewPage() {
|
||||
const dailyData = dailyRes?.data || []
|
||||
const comparisonData = comparisonRes?.data || []
|
||||
|
||||
// Initialize form when data loads or modal opens
|
||||
useEffect(() => {
|
||||
if (grid?.version && versionModalOpened) {
|
||||
setLatestVersion(grid.version.mobile_latest_version || '')
|
||||
setMinVersion(grid.version.mobile_minimum_version || '')
|
||||
setMessageUpdate(grid.version.mobile_message_update || '')
|
||||
setMaintenance(grid.version.mobile_maintenance === 'true')
|
||||
}
|
||||
}, [grid, versionModalOpened])
|
||||
|
||||
const handleRefresh = () => {
|
||||
mutateGrid()
|
||||
mutateDaily()
|
||||
mutateComparison()
|
||||
}
|
||||
|
||||
const handleSaveVersion = async () => {
|
||||
setIsSaving(true)
|
||||
try {
|
||||
const response = await fetch(API_URLS.postVersionUpdate(), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
mobile_latest_version: latestVersion,
|
||||
mobile_minimum_version: minVersion,
|
||||
mobile_maintenance: maintenance,
|
||||
mobile_message_update: messageUpdate,
|
||||
}),
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
notifications.show({
|
||||
title: 'Update Successful',
|
||||
message: 'Application version information has been updated.',
|
||||
color: 'teal',
|
||||
})
|
||||
mutateGrid()
|
||||
closeVersionModal()
|
||||
} else {
|
||||
notifications.show({
|
||||
title: 'Update Failed',
|
||||
message: 'Failed to update version information. Please check your data.',
|
||||
color: 'red',
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
notifications.show({
|
||||
title: 'Network Error',
|
||||
message: 'Could not connect to the server. Please try again later.',
|
||||
color: 'red',
|
||||
})
|
||||
} finally {
|
||||
setIsSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal opened={versionModalOpened} onClose={closeVersionModal} title="Update Version Information" radius="md">
|
||||
<Stack gap="md">
|
||||
<TextInput label="Active Version" defaultValue={grid?.version?.mobile_latest_version || 'v1.2.0'} />
|
||||
<TextInput label="Minimum Version" defaultValue={grid?.version?.mobile_minimum_version || 'v1.0.0'} />
|
||||
<TextInput
|
||||
label="Active Version"
|
||||
placeholder="e.g. 2.0.5"
|
||||
value={latestVersion}
|
||||
onChange={(e) => setLatestVersion(e.currentTarget.value)}
|
||||
/>
|
||||
<TextInput
|
||||
label="Minimum Version"
|
||||
placeholder="e.g. 2.0.0"
|
||||
value={minVersion}
|
||||
onChange={(e) => setMinVersion(e.currentTarget.value)}
|
||||
/>
|
||||
<Textarea
|
||||
label="Update Message"
|
||||
placeholder="Enter release notes or update message..."
|
||||
defaultValue={grid?.version?.mobile_message_update || ''}
|
||||
value={messageUpdate}
|
||||
onChange={(e) => setMessageUpdate(e.currentTarget.value)}
|
||||
minRows={3}
|
||||
autosize
|
||||
/>
|
||||
<Switch
|
||||
label="Maintenance Mode"
|
||||
description="Enable to put the app in maintenance mode for users."
|
||||
defaultChecked={grid?.version?.mobile_maintenance === 'true'}
|
||||
checked={maintenance}
|
||||
onChange={(e) => setMaintenance(e.currentTarget.checked)}
|
||||
/>
|
||||
<Button fullWidth onClick={closeVersionModal}>Save Changes</Button>
|
||||
<Button fullWidth onClick={handleSaveVersion} loading={isSaving}>Save Changes</Button>
|
||||
</Stack>
|
||||
</Modal>
|
||||
|
||||
@@ -84,11 +155,11 @@ function AppOverviewPage() {
|
||||
<Text size="sm" c="dimmed">Detailed metrics for {isDesaPlus ? 'Desa+' : appId}</Text>
|
||||
</Stack>
|
||||
|
||||
<Group gap="md">
|
||||
{/* <Group gap="md">
|
||||
<ActionIcon variant="light" color="brand-blue" size="lg" radius="md" onClick={handleRefresh}>
|
||||
<TbRefresh size={20} />
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
</Group> */}
|
||||
</Group>
|
||||
|
||||
<SimpleGrid cols={{ base: 1, sm: 2, lg: 4 }} spacing="lg">
|
||||
|
||||
Reference in New Issue
Block a user