Skip to content

Commit 5fa4114

Browse files
committed
refactor: removed var inAppConfig from hook
1 parent d7cd377 commit 5fa4114

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

src/pages/NotificationUserConfigPage/components/InAppNotificationUserConfigTab.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
77
import MenuBookIcon from '@mui/icons-material/MenuBook'
88
import { useNotificationInAppConfigForm } from '../hooks/useNotificationInAppConfigForm'
99
import { type NotificationConfig } from '@/api/api.generatedTypes'
10-
import React from 'react'
10+
import React, { useEffect } from 'react'
1111

1212
type InAppNotificationUserConfigTabProps = {
1313
inAppConfig: NotificationConfig
@@ -19,7 +19,6 @@ export type NotificationSubSectionSchema = {
1919
key: string
2020
title: string
2121
description: string
22-
defaultValue?: boolean
2322
}[]
2423
}
2524
export type NotificationSectionSchema = {
@@ -37,12 +36,19 @@ export type NotificationConfigSchema = {
3736
export const InAppNotificationUserConfigTab: React.FC<InAppNotificationUserConfigTabProps> = ({
3837
inAppConfig,
3938
}) => {
40-
const formMethods = useForm()
4139
const { t } = useTranslation('notification', { keyPrefix: 'configurationPage.inAppTab' })
4240

43-
const { notificationSchema } = useNotificationInAppConfigForm(inAppConfig)
41+
const { notificationSchema } = useNotificationInAppConfigForm()
4442

45-
const enableAllNotifications = formMethods.watch('enableShowNotification', true)
43+
const formMethods = useForm<NotificationConfig>({
44+
defaultValues: inAppConfig,
45+
})
46+
47+
const valueChanged = formMethods.watch()
48+
49+
useEffect(() => {
50+
console.log('valueChanged', valueChanged)
51+
}, [valueChanged])
4652

4753
return (
4854
<FormProvider {...formMethods}>
@@ -52,8 +58,8 @@ export const InAppNotificationUserConfigTab: React.FC<InAppNotificationUserConfi
5258
</Link>
5359
<Box sx={{ px: 3, mt: 2 }}>
5460
<RHFSwitch
55-
name="enableShowNotification"
56-
defaultChecked={enableAllNotifications}
61+
name="todo"
62+
defaultChecked={true}
5763
label={
5864
<SwitchLabelDescription
5965
label={t('enableAllNotifications.label')}
@@ -62,7 +68,7 @@ export const InAppNotificationUserConfigTab: React.FC<InAppNotificationUserConfi
6268
}
6369
/>
6470

65-
{enableAllNotifications &&
71+
{true &&
6672
Object.keys(notificationSchema).map((sectionName) => {
6773
return (
6874
<Box key={sectionName}>

src/pages/NotificationUserConfigPage/components/NotificationConfigSection.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { RHFSwitch, SwitchLabelDescription } from '@/components/shared/react-hook-form-inputs'
22
import { Box } from '@mui/system'
3-
import { useFormContext } from 'react-hook-form'
43
import { Typography } from '@mui/material'
54
import type { NotificationSubSectionSchema } from './InAppNotificationUserConfigTab'
65

@@ -21,7 +20,6 @@ export const NotificationConfigSection: React.FC<NotificationConfigSectionProps>
2120
sx={{ mt: 1, mb: 1 }}
2221
key={component.key}
2322
name={component.key}
24-
defaultChecked={component.defaultValue}
2523
label={
2624
<SwitchLabelDescription label={component.title} description={component.description} />
2725
}

src/pages/NotificationUserConfigPage/hooks/useNotificationInAppConfigForm.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { useTranslation } from 'react-i18next'
22
import { type NotificationConfigSchema } from '../components/InAppNotificationUserConfigTab'
3-
import type { NotificationConfig } from '@/api/api.generatedTypes'
43

5-
export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig) {
4+
export function useNotificationInAppConfigForm() {
65
const { t } = useTranslation('notification', { keyPrefix: 'configurationPage.inAppTab' })
76

87
const notificationSchema: NotificationConfigSchema = {
@@ -17,19 +16,16 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
1716
key: 'eserviceStateChangedToConsumer',
1817
title: t('subscriber.dataUsage.components.eServiceStateUpdated.label') + '(11)',
1918
description: t('subscriber.dataUsage.components.eServiceStateUpdated.description'),
20-
defaultValue: inAppConfig?.eserviceStateChangedToConsumer,
2119
},
2220
{
2321
key: 'agreementActivatedRejectedToConsumer',
2422
title: t('subscriber.dataUsage.components.agreementManagement.label') + '(12)',
2523
description: t('subscriber.dataUsage.components.agreementManagement.description'),
26-
defaultValue: inAppConfig?.agreementActivatedRejectedToConsumer,
2724
},
2825
{
2926
key: 'agreementSuspendedUnsuspendedToConsumer',
3027
title: t('subscriber.dataUsage.components.agreementStateUpdated.label') + '(13)',
3128
description: t('subscriber.dataUsage.components.agreementStateUpdated.description'),
32-
defaultValue: inAppConfig?.agreementSuspendedUnsuspendedToConsumer,
3329
},
3430
],
3531
},
@@ -41,13 +37,11 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
4137
key: 'purposeActivatedRejectedToConsumer',
4238
title: t('subscriber.purpose.components.purposeManagement.label') + '(15)',
4339
description: t('subscriber.purpose.components.purposeManagement.description'),
44-
defaultValue: inAppConfig?.purposeActivatedRejectedToConsumer,
4540
},
4641
{
4742
key: 'purposeSuspendedUnsuspendedToConsumer',
4843
title: t('subscriber.purpose.components.purposeStateUpdated.label') + '(16)',
4944
description: t('subscriber.purpose.components.purposeStateUpdated.description'),
50-
defaultValue: inAppConfig?.purposeSuspendedUnsuspendedToConsumer,
5145
},
5246
],
5347
},
@@ -82,13 +76,11 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
8276
key: 'agreementManagementToProducer',
8377
title: t('provider.agreement.components.agreementRequestReceived.label') + '(03)',
8478
description: t('provider.agreement.components.agreementRequestReceived.description'),
85-
defaultValue: inAppConfig.agreementManagementToProducer,
8679
},
8780
{
8881
key: 'agreementSuspendedUnsuspendedToProducer',
8982
title: t('provider.agreement.components.agreementStateUpdated.label') + '(04)',
9083
description: t('provider.agreement.components.agreementStateUpdated.description'),
91-
defaultValue: inAppConfig.agreementSuspendedUnsuspendedToProducer,
9284
},
9385
],
9486
},
@@ -100,7 +92,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
10092
key: 'purposeStatusChangedToProducer',
10193
title: t('provider.purpose.components.purposeStateUpdated.label') + '(07)',
10294
description: t('provider.purpose.components.purposeStateUpdated.description'),
103-
defaultValue: inAppConfig.purposeStatusChangedToProducer,
10495
},
10596
],
10697
},
@@ -116,7 +107,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
116107
description: t(
117108
'provider.clientAndThresholds.components.clientAssociationFromSubscriber.description'
118109
),
119-
defaultValue: inAppConfig.clientAddedRemovedToProducer,
120110
},
121111
{
122112
key: 'TODO',
@@ -146,15 +136,13 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
146136
description: t(
147137
'provider.eserviceTemplate.components.instanceFromTemplate.description'
148138
),
149-
defaultValue: inAppConfig.newEserviceTemplateVersionToInstantiator,
150139
},
151140
{
152141
key: 'eserviceTemplateStatusChangedToInstantiator',
153142
title: t('provider.eserviceTemplate.components.templateStateUpdated.label') + '(19)',
154143
description: t(
155144
'provider.eserviceTemplate.components.templateStateUpdated.description'
156145
),
157-
defaultValue: inAppConfig.eserviceTemplateStatusChangedToInstantiator,
158146
},
159147
{
160148
key: 'newTemplateVersion',
@@ -168,7 +156,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
168156
description: t(
169157
'provider.eserviceTemplate.components.templatePropertiesUpdated.description'
170158
),
171-
defaultValue: inAppConfig.eserviceTemplateNameChangedToInstantiator,
172159
},
173160
{
174161
key: 'templateStatusChangedToProducer',
@@ -178,7 +165,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
178165
description: t(
179166
'provider.eserviceTemplate.components.templateStateArchivedSuspended.description'
180167
),
181-
defaultValue: inAppConfig.templateStatusChangedToProducer,
182168
},
183169
],
184170
},
@@ -198,7 +184,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
198184
description: t(
199185
'delegation.delegationAssignment.components.delegationUpdated.description'
200186
),
201-
defaultValue: inAppConfig.delegationApprovedRejectedToDelegator,
202187
},
203188
{
204189
key: 'eserviceNewVersionSubmittedToDelegator',
@@ -208,7 +193,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
208193
description: t(
209194
'delegation.delegationAssignment.components.eserviceDelegatedCreated.description'
210195
),
211-
defaultValue: inAppConfig.eserviceNewVersionSubmittedToDelegator,
212196
},
213197
],
214198
},
@@ -222,7 +206,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
222206
description: t(
223207
'delegation.delegationReceive.components.delegationUpdated.description'
224208
),
225-
defaultValue: inAppConfig.delegationSubmittedRevokedToDelegate,
226209
},
227210
{
228211
key: 'eserviceNewVersionApprovedRejectedToDelegate',
@@ -232,7 +215,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
232215
description: t(
233216
'delegation.delegationReceive.components.eserviceDelegatedApproval.description'
234217
),
235-
defaultValue: inAppConfig.eserviceNewVersionApprovedRejectedToDelegate,
236218
},
237219
],
238220
},
@@ -252,7 +234,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
252234
description: t(
253235
'keyAndAttributes.attributes.components.attributesStateUpdated.description'
254236
),
255-
defaultValue: inAppConfig.certifiedVerifiedAttributeAssignedRevokedToAssignee,
256237
},
257238
],
258239
},
@@ -267,7 +248,6 @@ export function useNotificationInAppConfigForm(inAppConfig: NotificationConfig)
267248
description: t(
268249
'keyAndAttributes.keys.components.clientKeysAssociationUpdated.description'
269250
),
270-
defaultValue: inAppConfig.clientKeyAddedDeletedToClientUsers,
271251
},
272252
],
273253
},

0 commit comments

Comments
 (0)