-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add option to keep fwd email #253
Changes from all commits
c61f443
239d1c8
41df172
aa3c0f6
39abb57
a905164
c261d29
d842f3d
e6cac0d
84555b9
0baac94
641dcaf
097bca3
00d7e4f
0f31540
23ceba2
a4a9d13
ae15d4e
4ca2cf8
bce78ee
c26acc3
d2fc200
bb881d2
02e7112
691fa4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,5 @@ storybook-static | |
|
||
# netlify | ||
.netlify | ||
.aider* | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ import { | |
ViewPosition, | ||
} from 'types/schema' | ||
import { client, GET_PATHS } from 'libs/apis' | ||
import { ReactElement, useMemo, useState } from 'react' | ||
import { ReactElement, useRef, useMemo, useState } from 'react' | ||
import { | ||
EmployeeStatus, | ||
employeeStatuses, | ||
|
@@ -55,6 +55,7 @@ import { AuthenticatedContent } from 'components/common/AuthenticatedContent' | |
import { TotalResultCount } from 'components/common/Table/TotalResultCount' | ||
import { formatCurrency } from 'utils/currency' | ||
import { DEFAULT_CURRENCY_SYMBOL } from 'constants/currency' | ||
import { Modal } from 'antd' | ||
import { EditPersonalInfoModal } from './EditPersonalInfoModal' | ||
import { EditSkillsModal } from './EditSkillsModal' | ||
import { EditGeneralInfoModal } from './EditGeneralInfoModal' | ||
|
@@ -177,11 +178,52 @@ export const General = (props: Props) => { | |
mutate([GET_PATHS.getEmployees, data.username]) | ||
} | ||
|
||
const isKeepFwdEmailRef = useRef(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use state instead of ref ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was attempting to use the state hook, but it doesn’t work because of asynchronous data synchronization between the Modal and the main portal. Thanh suggested that I use the ref hook instead. |
||
|
||
const onChangeStatus = async (value: string) => { | ||
if (value === EmployeeStatus.LEFT) { | ||
// Reset the checkbox state before opening the modal | ||
isKeepFwdEmailRef.current = false | ||
|
||
Modal.confirm({ | ||
title: 'Confirm Employee Status Change', | ||
content: ( | ||
<div> | ||
<p>Are you sure you want to change the status to "Left"?</p> | ||
<div> | ||
<input | ||
type="checkbox" | ||
id="keepForwardEmailCheckbox" | ||
onChange={(e) => { | ||
isKeepFwdEmailRef.current = e.target.checked | ||
}} | ||
aria-label="Keep Forward Email" | ||
/> | ||
<label | ||
htmlFor="keepForwardEmailCheckbox" | ||
style={{ marginLeft: '8px', cursor: 'pointer' }} | ||
> | ||
Keep Forward Email | ||
</label> | ||
</div> | ||
</div> | ||
), | ||
onOk() { | ||
return updateEmployeeStatus(value); | ||
}, | ||
okText: 'Confirm', | ||
cancelText: 'Cancel', | ||
}); | ||
} else { | ||
await updateEmployeeStatus(value) | ||
} | ||
} | ||
|
||
const updateEmployeeStatus = async (value: string) => { | ||
try { | ||
setIsLoading(true) | ||
|
||
await client.updateEmployeeStatus(data.id || '', value) | ||
await client.updateEmployeeStatus(data.id || '', value, isKeepFwdEmailRef.current) | ||
|
||
// Refetch user data | ||
notification.success({ message: 'Employee status updated successfully!' }) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we change this? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid type assertion and simplify the code