Skip to content

Commit

Permalink
Delete DEVICE_AUTH_CODE_SESSION_KEY in ProvisionNewDevice modal (#1205)
Browse files Browse the repository at this point in the history
* ensure delete DEVICE_AUTH_CODE_SESSION_KEY on ProvisionNewDevice modal open event
  • Loading branch information
PatrikMatiasko authored Jan 28, 2024
1 parent 75b8fa5 commit 544cf4c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { updateLinkedHubData } from '@/containers/DeviceProvisioning/rest'
import PageLayout from '@/containers/Common/PageLayout'
import DetailHeader from '@/containers/DeviceProvisioning/LinkedHubs/DetailHeader'
import isEqual from 'lodash/isEqual'
import { FormContext } from '@shared-ui/common/context/FormContext'
import { FormContext, getFormContextDefault } from '@shared-ui/common/context/FormContext'

const Tab1 = lazy(() => import('./Tabs/Tab1/Tab1'))
const Tab2 = lazy(() => import('./Tabs/Tab2/Tab2'))
Expand Down Expand Up @@ -110,8 +110,8 @@ const LinkedHubsDetail: FC<any> = (props) => {

const context = useMemo(
() => ({
onSubmit: onSubmitForm,
updateData: (field: string, d: any) => console.log(field, d),
...getFormContextDefault('default'),
updateData: (data: any) => console.log(data),
}),
[]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const Tab1: FC<Props> = (props) => {
handleSubmit,
} = useForm<Inputs>({ mode: 'all', reValidateMode: 'onSubmit', values: defaultFormData })

const { onSubmit } = useContext(FormContext)
// const { onSubmit } = useContext(FormContext)

return (
<form onSubmit={handleSubmit(onSubmit)}>
<form>
<SimpleStripTable
rows={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TabContent1: FC<Props> = (props) => {
const { defaultFormData, loading } = props
const { formatMessage: _ } = useIntl()

const { onSubmit } = useContext(FormContext)
// const { onSubmit } = useContext(FormContext)

const {
formState: { errors, isDirty, touchedFields, dirtyFields, defaultValues },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const TabContent2: FC<Props> = (props) => {
control,
} = useForm<Inputs>({ mode: 'all', reValidateMode: 'onSubmit', values: defaultFormData })

const { onSubmit } = useContext(FormContext)
// const { onSubmit } = useContext(FormContext)

const defaultModalData = useMemo(
() => ({
Expand Down Expand Up @@ -77,7 +77,7 @@ const TabContent2: FC<Props> = (props) => {
}, [caPool, defaultModalData, modalData.value, setValue])

return (
<form onSubmit={handleSubmit(onSubmit)}>
<form>
<Headline type='h5'>{_(g.tls)}</Headline>
<p>Short description...</p>
<hr css={styles.separator} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { getApiErrorMessage } from '@shared-ui/common/utils'

import { getDeviceAuthCode } from '@/containers/Devices/rest'
import { messages as t } from '@/containers/Devices/Devices.i18n'
import { messages as g } from '@/containers/Global.i18n'
import notificationId from '@/notificationId'
import { DEVICE_AUTH_CODE_SESSION_KEY } from '@/constants'

const ProvisionNewDeviceCore = () => {
const [show, setShow] = useState(false)
Expand Down Expand Up @@ -44,12 +46,16 @@ const ProvisionNewDeviceCore = () => {

const openModal = () => {
setShow(true)
localStorage.removeItem(DEVICE_AUTH_CODE_SESSION_KEY)
sessionStorage.removeItem(DEVICE_AUTH_CODE_SESSION_KEY)
inputRef?.current?.focus()
}

const onClose = () => {
setShow(false)
setCode(undefined)
localStorage.removeItem(DEVICE_AUTH_CODE_SESSION_KEY)
sessionStorage.removeItem(DEVICE_AUTH_CODE_SESSION_KEY)
setDeviceId(null)
}

Expand All @@ -62,7 +68,7 @@ const ProvisionNewDeviceCore = () => {
{_(t.addDevice)}
</Button>
<ProvisionDeviceModal
closeButtonText={_(t.cancel)}
closeButtonText={_(g.close)}
deviceAuthCode={code}
deviceAuthLoading={fetching}
deviceInformation={
Expand All @@ -84,13 +90,8 @@ const ProvisionNewDeviceCore = () => {
}
footerActions={[
{
label: _(t.cancel),
onClick: () => setShow(false),
variant: 'tertiary',
},
{
label: _(t.delete),
onClick: () => setShow(false),
label: _(t.close),
onClick: onClose,
variant: 'primary',
},
]}
Expand Down
1 change: 1 addition & 0 deletions http-gateway/web/src/containers/Devices/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export const getDeviceAuthCode = (deviceId: string) => {

const destroyIframe = () => {
sessionStorage.removeItem(DEVICE_AUTH_CODE_SESSION_KEY)
localStorage.removeItem(DEVICE_AUTH_CODE_SESSION_KEY)
iframe.parentNode?.removeChild(iframe)
}

Expand Down

0 comments on commit 544cf4c

Please sign in to comment.