Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 20 additions & 103 deletions src/pages/cipp/super-admin/time-settings.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { TabbedLayout } from '../../../layouts/TabbedLayout'
import { Layout as DashboardLayout } from '../../../layouts/index.js'
import { useForm } from 'react-hook-form'
import { Alert, Typography } from '@mui/material'
import { Grid } from '@mui/system'
import CippFormComponent from '../../../components/CippComponents/CippFormComponent'
import { ApiGetCall } from '../../../api/ApiCall'
import { useEffect, useMemo } from 'react'
import { useEffect } from 'react'
import CippFormPage from '../../../components/CippFormPages/CippFormPage'
import { useTimezones } from '../../../hooks/use-timezones'
import tabOptions from './tabOptions'
import { Alert, Typography } from '@mui/material'

const Page = () => {
const pageTitle = 'Time Settings'
Expand All @@ -17,7 +17,6 @@ const Page = () => {
mode: 'onChange',
defaultValues: {
Timezone: { label: 'UTC', value: 'UTC' },
BusinessHoursStart: { label: '09:00', value: '09:00' },
},
})

Expand All @@ -28,21 +27,6 @@ const Page = () => {
})

const { timezones, loading: timezonesLoading } = useTimezones()
const isFlexConsumption = backendInfo.data?.Results?.SKU === 'FlexConsumption'
const isLinuxConsumption = backendInfo.data?.Results?.OS === 'Linux' && !isFlexConsumption

// Generate business hours options (00:00 to 23:00 in hourly increments)
const businessHoursOptions = useMemo(() => {
const hours = []
for (let i = 0; i < 24; i++) {
const hour = i.toString().padStart(2, '0')
hours.push({
label: `${hour}:00`,
value: `${hour}:00`,
})
}
return hours
}, [])

useEffect(() => {
if (backendInfo.isSuccess && backendInfo.data) {
Expand All @@ -53,19 +37,9 @@ const Page = () => {
label: tzStr,
value: tzStr,
}

const startStr = backendInfo.data?.Results?.BusinessHoursStart || '09:00'
const startOption = businessHoursOptions.find((o) => o.value === startStr) || {
label: startStr,
value: startStr,
}

formControl.reset({
Timezone: tzOption,
BusinessHoursStart: startOption,
})
formControl.reset({ Timezone: tzOption })
}
}, [backendInfo.isSuccess, backendInfo.data, timezones, businessHoursOptions])
}, [backendInfo.isSuccess, backendInfo.data, timezones])

return (
<CippFormPage
Expand All @@ -79,11 +53,10 @@ const Page = () => {
>
<Grid container spacing={2} sx={{ mb: 3 }}>
<Grid size={12}>
<Typography variant="body1">
Configure the timezone for CIPP operations and scheduling. If you are using a Flex
Consumption App Service Plan, you can also configure business hours to optimize
performance and cost.
</Typography>
<Alert severity="info">
Configure the timezone for CIPP. This setting will determine which timezone is used when
background tasks run. If no timezone is selected, UTC will be used by default.
</Alert>
</Grid>

{!backendInfo.isSuccess && (
Expand All @@ -99,74 +72,18 @@ const Page = () => {
)}

{backendInfo.isSuccess && (
<>
{isLinuxConsumption ? (
<Grid size={12}>
<Alert severity="warning">
<Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 1 }}>
Timezone Not Supported
</Typography>
The <strong>WEBSITE_TIME_ZONE</strong> setting is not supported on Linux
Consumption function apps. Timezone configuration is only available on Windows
plans, Premium Linux plans, and Flex Consumption plans.
</Alert>
</Grid>
) : (
<Grid size={12}>
<CippFormComponent
type="autoComplete"
name="Timezone"
label="Timezone"
multiple={false}
formControl={formControl}
options={timezones?.length ? timezones : [{ label: 'UTC', value: 'UTC' }]}
creatable={false}
validators={{ required: 'Please select a timezone' }}
/>
</Grid>
)}

{isFlexConsumption && (
<>
<Grid size={12}>
<Alert severity="info" sx={{ mt: 2 }}>
<Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 1 }}>
Flex Consumption Business Hours
</Typography>
Business hours are used to optimize Flex Consumption instance scheduling. Set
the start time for your business hours. CIPP will maintain higher instance
availability during a 10-hour window from the start time for better performance.
Outside of this window, instances may scale down to reduce costs.
</Alert>
</Grid>

<Grid size={{ xs: 12, md: 6 }}>
<CippFormComponent
type="autoComplete"
name="BusinessHoursStart"
label="Business Hours Start Time (10-hour window)"
formControl={formControl}
options={businessHoursOptions}
validators={{ required: 'Please select business hours start time' }}
multiple={false}
creatable={false}
/>
</Grid>
</>
)}

{!isFlexConsumption && (
<Grid size={12}>
<Alert severity="info">
<Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 1 }}>
App Service Plan: {backendInfo.data?.SKU || 'Unknown'}
</Typography>
Business hours configuration is only available for Flex Consumption App Service
Plans.
</Alert>
</Grid>
)}
</>
<Grid size={12}>
<CippFormComponent
type="autoComplete"
name="Timezone"
label="Timezone"
multiple={false}
formControl={formControl}
options={timezones?.length ? timezones : [{ label: 'UTC', value: 'UTC' }]}
creatable={false}
validators={{ required: 'Please select a timezone' }}
/>
</Grid>
)}
</Grid>
</CippFormPage>
Expand Down