Skip to content

Advanced Out of Office Editor #1804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
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
243 changes: 242 additions & 1 deletion src/views/email-exchange/administration/EditMailboxPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { Form, Field } from 'react-final-form'
import { RFFSelectSearch, RFFCFormSelect, RFFCFormCheck, RFFCFormInput } from 'src/components/forms'
import { useListUsersQuery } from 'src/store/api/users'
import { ModalService } from 'src/components/utilities'
import { useLazyGenericPostRequestQuery, useLazyGenericGetRequestQuery } from 'src/store/api/app'
import {
useLazyGenericPostRequestQuery,
useLazyGenericGetRequestQuery,
useGenericGetRequestQuery,
} from 'src/store/api/app'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
import {
Expand All @@ -32,6 +36,9 @@ import {
import { CippTable } from 'src/components/tables'
import { useListMailboxDetailsQuery } from 'src/store/api/mailbox'
import { CellBoolean } from 'src/components/tables'
import DatePicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
import { RFFCFormSwitch } from 'src/components/forms'

const formatter = (cell, warning = false, reverse = false, colourless = false) =>
CellBoolean({ cell, warning, reverse, colourless })
Expand Down Expand Up @@ -114,6 +121,9 @@ const MailboxSettings = () => {
<CNavItem active={active === 3} onClick={() => setActive(3)} href="#">
Mailbox Forwarding
</CNavItem>
<CNavItem active={active === 4} onClick={() => setActive(4)} href="#">
Out Of Office
</CNavItem>
</CNav>
</CCardHeader>
<CCardBody>
Expand All @@ -127,6 +137,9 @@ const MailboxSettings = () => {
<CTabPane visible={active === 3} className="mt-3">
<MailboxForwarding />
</CTabPane>
<CTabPane visible={active === 4} className="mt-3">
<OutOfOffice />
</CTabPane>
</CTabContent>
</CCardBody>
</CCard>
Expand Down Expand Up @@ -158,6 +171,11 @@ const MailboxSettings = () => {
<ForwardingSettings userId={userId} tenantDomain={tenantDomain} />
</>
)}
{active === 4 && (
<>
<OutOfOfficeSettings userId={userId} tenantDomain={tenantDomain} />
</>
)}
</CCardBody>
</CCard>
</CCol>
Expand Down Expand Up @@ -761,3 +779,226 @@ const ForwardingSettings = () => {
</CRow>
)
}

const OutOfOffice = () => {
const dispatch = useDispatch()
let query = useQuery()
const userId = query.get('userId')
const tenantDomain = query.get('tenantDomain')
const [queryError, setQueryError] = useState(false)
const [genericPostRequest, postResults] = useLazyGenericPostRequestQuery()
const [startDate, setStartDate] = useState(new Date())
const [endDate, setEndDate] = useState(new Date())
const {
data: user = {},
isFetching: userIsFetching,
error: userError,
} = useListMailboxPermissionsQuery({ tenantDomain, userId })

const {
data: users = [],
isFetching: usersIsFetching,
error: usersError,
} = useListUsersQuery({ tenantDomain })

useEffect(() => {
if (postResults.isSuccess) {
}
if (!userId || !tenantDomain) {
ModalService.open({
body: 'Error invalid request, could not load requested user.',
title: 'Invalid Request',
})
setQueryError(true)
} else {
setQueryError(false)
}
}, [userId, tenantDomain, dispatch, postResults])
const onSubmit = (values) => {
const shippedValues = {
user: userId,
tenantFilter: tenantDomain,
AutoReplyState: values.AutoReplyState ? 'Scheduled' : 'Disabled',
StartTime: startDate.toLocaleString(),
EndTime: endDate.toLocaleString(),
InternalMessage: values.InternalMessage ? values.InternalMessage : '',
ExternalMessage: values.ExternalMessage ? values.ExternalMessage : '',
}
//window.alert(JSON.stringify(shippedValues))
genericPostRequest({ path: '/api/ExecSetOoO', values: shippedValues })
}
const initialState = {
...user,
}

const formDisabled = queryError === true

return (
<>
{!queryError && (
<>
{queryError && (
<CRow>
<CCol className="mb-3">
<CCallout color="danger">
{/* @todo add more descriptive help message here */}
Failed to load user
</CCallout>
</CCol>
</CRow>
)}
<CRow>
<CCol className="mb-3">
{usersIsFetching && <CSpinner />}
{userError && <span>Error loading user</span>}
{!usersIsFetching && (
<Form
initialValues={{ ...initialState }}
onSubmit={onSubmit}
render={({ handleSubmit, submitting, values }) => {
return (
<CForm onSubmit={handleSubmit}>
<CRow>
<CCol className="mb-3">
<RFFCFormSwitch name="AutoReplyState" label="Auto Reply State" />
</CCol>
</CRow>
<CRow>
<CCol className="mb-3">
<label>Start Date/Time</label>
<DatePicker
dateFormat="dd/MM/yyyy HH:mm"
className="form-control"
selected={startDate}
onChange={(date) => setStartDate(date)}
showTimeSelect
/>
</CCol>
</CRow>
<CRow>
<CCol className="mb-3">
<label>End Date/Time</label>
<DatePicker
dateFormat="dd/MM/yyyy HH:mm"
className="form-control"
selected={endDate}
onChange={(date) => setEndDate(date)}
showTimeSelect
/>
</CCol>
</CRow>
<CRow>
<CCol className="mb-3">
<RFFCFormInput
type="text"
name="InternalMessage"
label="Internal Message"
disabled={formDisabled}
/>
</CCol>
</CRow>
<CRow>
<CCol className="mb-3">
<RFFCFormInput
type="text"
name="ExternalMessage"
label="External Message"
disabled={formDisabled}
/>
</CCol>
</CRow>
<CRow>
<CCol className="mb-3">
<CButton
type="submit"
disabled={submitting || formDisabled}
style={{ marginRight: '10px' }}
>
Edit Out of Office
{postResults.isFetching && (
<FontAwesomeIcon
icon={faCircleNotch}
spin
className="me-2"
size="1x"
/>
)}
</CButton>
</CCol>
</CRow>
{postResults.isSuccess && (
<CCallout color="success">
{postResults.data.Results.map((result, idx) => (
<li key={idx}>{result}</li>
))}
</CCallout>
)}
</CForm>
)
}}
/>
)}
</CCol>
</CRow>
</>
)}
</>
)
}

const OutOfOfficeSettings = () => {
const query = useQuery()
const userId = query.get('userId')
const tenantDomain = query.get('tenantDomain')
const tenantFilter = tenantDomain
const {
data: details,
isFetching,
error,
} = useGenericGetRequestQuery({
path: '/api/ListOoO',
params: { userId, tenantFilter },
})
const content = [
{
heading: 'Auto Reply State',
body: formatter(details?.AutoReplyState, false, false, true),
},
{
heading: 'Start Date/Time',
body: details?.StartTime ? details?.StartTime : 'N/A',
},
{
heading: 'End Date/Time',
body: details?.EndTime ? details?.EndTime : 'N/A',
},
{
heading: 'Internal Message',
body: details?.InternalMessage ? details?.InternalMessage : 'N/A',
},
{
heading: 'External Message',
body: details?.ExternalMessage ? details?.ExternalMessage : 'N/A',
},
]
return (
<CRow>
{isFetching && (
<CCallout color="info">
<CSpinner>Loading</CSpinner>
</CCallout>
)}
{!isFetching && (
<CCol className="mb-3">
{content.map((item, index) => (
<div key={index}>
<h5>{item.heading}</h5>
<p>{item.body}</p>
</div>
))}
</CCol>
)}
{error && <CCallout color="danger">Could not connect to API: {error.message}</CCallout>}
</CRow>
)
}
3 changes: 2 additions & 1 deletion src/views/identity/administration/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const Offcanvas = (row, rowIndex, formatExtraData) => {
user: row.userPrincipalName,
TenantFilter: tenant.defaultDomainName,
message: row.message,
AutoReplyState: 'Enabled',
},
modalUrl: `/api/ExecSetOoO`,
modalInput: true,
Expand All @@ -163,7 +164,7 @@ const Offcanvas = (row, rowIndex, formatExtraData) => {
modalBody: {
user: row.userPrincipalName,
TenantFilter: tenant.defaultDomainName,
Disable: true,
AutoReplyState: 'Disabled',
},
modalUrl: `/api/ExecSetOoO`,
modalMessage: 'Are you sure you want to disable the out of office?',
Expand Down