Skip to content
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(my-pages-health): integrate new modal in health center registration #17402

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions libs/feature-flags/src/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export enum Features {
licenseServiceDrivingLicenseClient = 'isLicenseServiceDrivingLicenceClientV2Enabled',
licenseServiceDrivingLicencePhotoCheckDisabled = 'isLicenseServiceDrivingLicencePhotoCheckDisabled',

//Use new modal for health
isServicePortalHealthCenterRegistrationModalV2Enabled = 'isServicePortalHealthCenterRegistrationModalV2Enabled',

//Enable intellectual properties fetch
isIntellectualPropertyModuleEnabled = 'isIntellectualPropertyModuleEnabled',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { style } from '@vanilla-extract/css'
import { theme, themeUtils } from '@island.is/island-ui/theme'

export const modal = style({
position: 'relative',
position: 'absolute',
maxWidth: `calc(100% - ${theme.spacing['6']}px)`,
maxHeight: `calc(100% - ${theme.spacing['6']}px)`,
margin: theme.spacing['3'],
borderRadius: theme.border.radius.large,
top: '40%',
left: '50%',
transform: 'translate(-50%, -50%)',
overflowY: 'auto',
boxShadow: '0px 4px 70px rgba(0, 97, 255, 0.1)',
...themeUtils.responsiveStyle({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
Button,
FilterInput,
Tooltip,
Select,
} from '@island.is/island-ui/core'
import { useLocale, useNamespaces } from '@island.is/localization'
import { IntroHeader } from '@island.is/portals/core'
import {
EmptyState,
ErrorScreen,
ExcludesFalse,
Modal,
} from '@island.is/portals/my-pages/core'
import { messages } from '../../lib/messages'
import * as styles from './HealthRegistration.css'
Expand All @@ -33,6 +35,7 @@ import {
useGetHealthCenterQuery,
useRightsPortalTransferHealthCenterMutation,
} from './HealthCenterRegistration.generated'
import { Features, useFeatureFlagClient } from '@island.is/react/feature-flags'

type SelectedHealthCenter = Pick<RightsPortalHealthCenter, 'id' | 'name'>

Expand Down Expand Up @@ -65,6 +68,26 @@ const HealthCenterRegistration = () => {
HealthCenterDoctorOption[]
>([])

const [selectedHealthCenterDoctor, setSelectedHealthCenterDoctor] = useState<
number | undefined
>()

const [useModalV2, setUseModalV2] = useState<boolean>(false)
const featureFlagClient = useFeatureFlagClient()
useEffect(() => {
const isFlagEnabled = async () => {
const ffEnabled = await featureFlagClient.getValue(
Features.isServicePortalHealthCenterRegistrationModalV2Enabled,
false,
)
if (ffEnabled) {
setUseModalV2(ffEnabled as boolean)
}
}
isFlagEnabled()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

const handleOnError = () => {
setSelectedHealthCenter(null)
setLoadingTransfer(false)
Expand Down Expand Up @@ -132,14 +155,15 @@ const HealthCenterRegistration = () => {
}
}, [errorTransfer])

//todo: remove doctorId when V2 open
const handleHealthCenterTransfer = async (doctorId?: number) => {
setLoadingTransfer(true)
if (selectedHealthCenter && selectedHealthCenter?.id) {
if (selectedHealthCenter?.id) {
await transferHealthCenter({
variables: {
input: {
id: selectedHealthCenter.id,
doctorId: doctorId,
doctorId: useModalV2 ? selectedHealthCenterDoctor : doctorId,
},
},
})
Expand Down Expand Up @@ -242,22 +266,25 @@ const HealthCenterRegistration = () => {
</Box>
</Box>
)}

<RegisterModal
id="healthCenterDialog"
title={formatMessage(messages.healthCenterRegistrationModalTitle, {
healthCenter: selectedHealthCenter?.name,
})}
description={formatMessage(messages.healthCenterRegistrationModalInfo)}
onClose={() => {
setSelectedHealthCenter(null)
setHealthCenterDoctors([])
}}
onAccept={handleHealthCenterTransfer}
isVisible={!!selectedHealthCenter}
buttonLoading={loadingTransfer}
healthCenterDoctors={healthCenterDoctors}
/>
{!useModalV2 && (
<RegisterModal
id="healthCenterDialog"
title={formatMessage(messages.healthCenterRegistrationModalTitle, {
healthCenter: selectedHealthCenter?.name,
})}
description={formatMessage(
messages.healthCenterRegistrationModalInfo,
)}
onClose={() => {
setSelectedHealthCenter(null)
setHealthCenterDoctors([])
}}
onAccept={handleHealthCenterTransfer}
isVisible={!!selectedHealthCenter}
buttonLoading={loadingTransfer}
healthCenterDoctors={healthCenterDoctors}
/>
)}

<Box className={styles.filterWrapperStyle} marginBottom={3}>
<FilterInput
Expand Down Expand Up @@ -323,46 +350,132 @@ const HealthCenterRegistration = () => {
</Text>
</T.Data>
<T.Data>
{healthCenter.canRegister ? (
<Box
className={styles.saveButtonWrapperStyle({
visible: healthCenter.id === hoverId,
})}
>
<Button
size="small"
variant="text"
icon="pencil"
onClick={() =>
handleHealthCenterSelect(
healthCenter.id,
healthCenter.name,
)
}
<Box
className={styles.saveButtonWrapperStyle({
visible: healthCenter.id === hoverId,
})}
>
{!useModalV2 && healthCenter.canRegister && (
<Box
className={styles.saveButtonWrapperStyle({
visible: healthCenter.id === hoverId,
})}
>
<Button
size="small"
variant="text"
icon="pencil"
onClick={() =>
handleHealthCenterSelect(
healthCenter.id,
healthCenter.name,
)
}
>
{formatMessage(
messages.healthRegistrationSave,
)}
</Button>
</Box>
)}
{!useModalV2 && !healthCenter.canRegister && (
<Text
variant="medium"
aria-label={formatMessage(
messages.healthCenterNotAvailableForRegistration,
)}
>
{formatMessage(
messages.healthRegistrationSave,
messages.healthCenterNotAvailableForRegistration,
)}
</Button>
</Box>
) : (
<Text
variant="medium"
aria-label={formatMessage(
messages.healthCenterNotAvailableForRegistration,
)}
>
{formatMessage(
messages.healthCenterNotAvailableForRegistration,
)}
<Tooltip
text={formatMessage(
messages.healthCenterNotAvailableForRegistrationDesc,
<Tooltip
text={formatMessage(
messages.healthCenterNotAvailableForRegistrationDesc,
)}
placement="right"
/>
</Text>
)}
{useModalV2 && (
<Modal
id={'healthCenterRegisterModal'}
initialVisibility={false}
iconSrc="./assets/images/coffee.svg"
iconAlt="coffee"
toggleClose={!selectedHealthCenter}
onCloseModal={() => {
setSelectedHealthCenter(null)
setHealthCenterDoctors([])
}}
title={formatMessage(
messages.healthCenterRegistrationModalTitle,
{
healthCenter:
selectedHealthCenter?.name,
},
)}
placement="right"
/>
</Text>
)}
buttons={[
{
id: 'RegisterHealthCenterModalAccept',
type: 'primary' as const,
text: formatMessage(
messages.healthRegisterModalAccept,
),
onClick: handleHealthCenterTransfer,
},
{
id: 'RegisterHealthCenterModalDecline',
type: 'ghost' as const,
text: formatMessage(
messages.healthRegisterModalDecline,
),
onClick: () => {
setSelectedHealthCenter(null)
setHealthCenterDoctors([])
},
},
]}
disclosure={
<Button
size="small"
variant="text"
icon="pencil"
onClick={() => {
setSelectedHealthCenter({
id: healthCenter.id,
name: healthCenter.name,
})
}}
>
{formatMessage(
messages.healthRegistrationSave,
)}
</Button>
}
>
{healthCenterDoctors?.length ? (
<Box marginBottom={4}>
<Select
size="xs"
isClearable
options={healthCenterDoctors}
label={formatMessage(
messages.chooseDoctorLabel,
)}
placeholder={formatMessage(
messages.chooseDoctorPlaceholder,
)}
onChange={(val) => {
setSelectedHealthCenterDoctor(
val?.value,
)
}}
/>
</Box>
) : null}
</Modal>
)}
</Box>
</T.Data>
</tr>
)
Expand Down
Loading