refactor(alert-settings): integrate AppShell layout and update cache version
Some checks failed
Deploy MyApp on Same Server / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy MyApp on Same Server / build-and-deploy (push) Has been cancelled
- Replace custom page layout with AppShell component for consistent UI - Remove unused PageHeader and UpdateAlertConditionDto imports - Update service worker cache names and version.json to new timestamp
This commit is contained in:
@@ -6,6 +6,7 @@ import { Smartphone, ArrowLeft } from 'lucide-react'
|
||||
import Loading from '@/components/Loading'
|
||||
import { MobileInput } from '@/components/forms'
|
||||
import { ErrorMessage } from '@/components/common'
|
||||
import { getCurrentPersianYear, getCurrentPersianMonth, getCurrentPersianDay } from '@/lib/date/persian-date'
|
||||
|
||||
export default function Home() {
|
||||
const router = useRouter()
|
||||
@@ -20,9 +21,35 @@ export default function Home() {
|
||||
|
||||
if (token && userStr) {
|
||||
try {
|
||||
JSON.parse(userStr)
|
||||
// Redirect to devices check
|
||||
router.push('/devices')
|
||||
const user = JSON.parse(userStr)
|
||||
|
||||
// Try to use the saved device from localStorage first
|
||||
const savedDeviceId = localStorage.getItem('selectedDeviceId')
|
||||
if (savedDeviceId) {
|
||||
const today = `${getCurrentPersianYear()}/${String(getCurrentPersianMonth()).padStart(2, '0')}/${String(getCurrentPersianDay()).padStart(2, '0')}`
|
||||
router.push(`/daily-report?deviceId=${savedDeviceId}&date=${encodeURIComponent(today)}`)
|
||||
return
|
||||
}
|
||||
|
||||
// No saved device — fetch user devices and auto-select the first one
|
||||
api.getUserDevices(user.id)
|
||||
.then((devices) => {
|
||||
if (devices.length > 0) {
|
||||
const firstDevice = devices[0]
|
||||
// Save to localStorage
|
||||
localStorage.setItem('selectedDeviceId', String(firstDevice.id))
|
||||
localStorage.setItem('selectedDeviceName', firstDevice.deviceName)
|
||||
const today = `${getCurrentPersianYear()}/${String(getCurrentPersianMonth()).padStart(2, '0')}/${String(getCurrentPersianDay()).padStart(2, '0')}`
|
||||
router.push(`/daily-report?deviceId=${firstDevice.id}&date=${encodeURIComponent(today)}`)
|
||||
} else {
|
||||
// No devices — go to devices page to show the error
|
||||
router.push('/devices')
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// On error, fall back to devices page
|
||||
router.push('/devices')
|
||||
})
|
||||
} catch {
|
||||
// Invalid user data, go to login
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user