-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new UI for notification settings page
- Loading branch information
1 parent
865e802
commit 8c2628c
Showing
32 changed files
with
1,261 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { FC } from 'react'; | ||
import { IconWrapper } from '../IconWrapper'; | ||
import { IconProps } from '../Icons.types'; | ||
|
||
const Pencil: FC<IconProps> = (allProps) => { | ||
const { svgProps: props, ...restProps } = allProps; | ||
return ( | ||
<IconWrapper | ||
componentName="Pencil" | ||
icon={ | ||
<svg | ||
width="inherit" | ||
height="inherit" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
d="M8.47489 20.25H4.46739C4.27712 20.25 4.09465 20.1744 3.96012 20.0399C3.82558 19.9053 3.75 19.7229 3.75 19.5326V15.5251C3.75009 15.3351 3.82555 15.1529 3.95984 15.0185L15.0183 3.95995C15.1529 3.82552 15.3353 3.75 15.5254 3.75C15.7156 3.75 15.898 3.82552 16.0325 3.95995L20.04 7.96476C20.1745 8.09928 20.25 8.28168 20.25 8.47186C20.25 8.66204 20.1745 8.84444 20.04 8.97896L8.98154 20.0402C8.84711 20.1744 8.66489 20.2499 8.47489 20.25Z" | ||
stroke="currentColor" | ||
stroke-width="1.5" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
/> | ||
<path | ||
d="M12.3589 6.61963L17.3806 11.6413" | ||
stroke="currentColor" | ||
stroke-width="1.5" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
/> | ||
</svg> | ||
} | ||
{...restProps} | ||
/> | ||
); | ||
}; | ||
|
||
export default Pencil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type ModalResponse = { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
open: () => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { useIsVisible } from './useIsVisible'; | ||
export { usePushStakingStats } from './usePushStakingStats'; | ||
export { useModal } from './useModal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ModalResponse } from 'common/common.types'; | ||
import { useState, useCallback } from 'react'; | ||
|
||
const useModal = (): ModalResponse => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const open = useCallback(() => setIsOpen(true), []); | ||
const onClose = useCallback(() => setIsOpen(false), []); | ||
|
||
return { | ||
isOpen, | ||
onClose, | ||
open, | ||
}; | ||
}; | ||
|
||
export { useModal }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/modules/notifSettings/EditNotificationSetting.form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { FC } from 'react'; | ||
|
||
import { FormikProvider, useFormik, useFormikContext } from 'formik'; | ||
|
||
import { ChannelSetting } from 'modules/channelDashboard/ChannelDashboard.types'; | ||
|
||
type EditNotificationSettingsFormProviderProps = { | ||
children: React.ReactNode; | ||
initialValue: ChannelSetting; | ||
onSubmit: (values: NotificationSettingFormValues) => void; | ||
}; | ||
|
||
export const getFormInitialValus = (initialValue: ChannelSetting): NotificationSettingFormValues => { | ||
return { | ||
settingName: initialValue.description, | ||
isDefault: | ||
initialValue.type === 1 ? (typeof initialValue.default === 'boolean' ? true : false) : initialValue.enabled!, | ||
enableRange: initialValue.type !== 1 ? true : false, | ||
rangelowerlimit: initialValue.lowerLimit ? initialValue.lowerLimit : 0, | ||
rangeupperlimit: initialValue.upperLimit ? initialValue.upperLimit : 0, | ||
enableMultiRange: initialValue.type === 3 ? true : false, | ||
defaultValue: typeof initialValue.default === 'number' ? initialValue.default : 0, | ||
multirangelowerlimit: typeof initialValue.default === 'object' ? initialValue.default.lower : 0, | ||
multirangeupperlimit: typeof initialValue.default === 'object' ? initialValue.default.upper : 0, | ||
sliderStepValue: initialValue.ticker ? initialValue.ticker : 0, | ||
}; | ||
}; | ||
|
||
const EditNotificationSettingsFormProvider: FC<EditNotificationSettingsFormProviderProps> = ({ | ||
children, | ||
initialValue, | ||
onSubmit, | ||
}) => { | ||
const addNotificationSettingsForm = useFormik<NotificationSettingFormValues>({ | ||
initialValues: getFormInitialValus(initialValue), | ||
onSubmit: onSubmit, | ||
}); | ||
|
||
return <FormikProvider value={addNotificationSettingsForm}>{children}</FormikProvider>; | ||
}; | ||
|
||
const useEditNotificationSettingsForm = () => { | ||
const context = useFormikContext<NotificationSettingFormValues>(); | ||
|
||
if (!context) { | ||
throw new Error('useEditNotificationSettingsForm must be used within a EditNotificationSettingsFormProvider'); | ||
} | ||
return context; | ||
}; | ||
|
||
export { useEditNotificationSettingsForm, EditNotificationSettingsFormProvider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const settingInitialValue = { | ||
type: 1, | ||
default: 0, | ||
description: '', | ||
index: 0, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useState } from 'react'; | ||
|
||
import { Box } from 'blocks'; | ||
|
||
import { useModal } from 'common'; | ||
|
||
import { useAccount } from 'hooks'; | ||
|
||
import { useGetChannelDetails } from 'queries'; | ||
|
||
import { NotificationSettingsHeader } from './components/NotificationSettingsHeader'; | ||
import { NotificationSettingsBody } from './components/NotificationSettingsBody'; | ||
import { ChannelSetting } from 'modules/channelDashboard/ChannelDashboard.types'; | ||
import { settingInitialValue } from './NotificationSettings.constants'; | ||
|
||
const NotificationSettings = () => { | ||
const { account } = useAccount(); | ||
|
||
const { data: channelDetails, isLoading: loadingChannelDetails } = useGetChannelDetails(account); | ||
const channelSettings = channelDetails?.channel_settings ? channelDetails?.channel_settings : ''; | ||
|
||
const modifiedChannelSettings = loadingChannelDetails | ||
? Array(3).fill(0) | ||
: channelSettings | ||
? JSON.parse(channelSettings) | ||
: []; | ||
|
||
const modalControl = useModal(); | ||
|
||
const [settingsToEdit, setSettingsToEdit] = useState<ChannelSetting>(settingInitialValue); | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
padding={{ initial: 'spacing-lg', ml: 'spacing-md' }} | ||
flexDirection="column" | ||
gap="spacing-md" | ||
width={{ ml: '357px', initial: '800px' }} | ||
alignItems="center" | ||
borderRadius="radius-md" | ||
backgroundColor="surface-primary" | ||
> | ||
<NotificationSettingsHeader | ||
modalControl={modalControl} | ||
setSettingsToEdit={setSettingsToEdit} | ||
/> | ||
|
||
<NotificationSettingsBody | ||
modalControl={modalControl} | ||
settingsToEdit={settingsToEdit} | ||
setSettingsToEdit={setSettingsToEdit} | ||
channelSettings={modifiedChannelSettings} | ||
loadingSettings={loadingChannelDetails} | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
export { NotificationSettings }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
type NotificationSettingFormValues = { | ||
settingName: string; | ||
isDefault: boolean; | ||
enableRange: boolean; | ||
rangelowerlimit: number; | ||
rangeupperlimit: number; | ||
enableMultiRange: boolean; | ||
defaultValue: number; | ||
multirangelowerlimit: number; | ||
multirangeupperlimit: number; | ||
sliderStepValue: number; | ||
}; | ||
|
||
type NotificationSettings = { | ||
type: number; | ||
default: | ||
| boolean | ||
| number | ||
| { | ||
lower: number; | ||
upper: number; | ||
}; | ||
enabled?: boolean; | ||
description: string; | ||
index?: number; | ||
lowerLimit?: number; | ||
upperLimit?: number; | ||
ticker?: number; | ||
}; | ||
|
||
type NotificationSettingModal = { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
open: () => void; | ||
}; |
Oops, something went wrong.