Skip to content

Commit

Permalink
Merge pull request #403 from WalletConnect/refactor/add-save-function…
Browse files Browse the repository at this point in the history
…ality-for-app-settings

feat: add save button functionality to domains settings
  • Loading branch information
enesozturk authored Jan 15, 2024
2 parents c273227 + 304ac3f commit 047faf4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/components/general/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
color: var(--fg-color-5);
}

&__outline {
background: transparent;
border: 1px solid var(--accent-color-1);
color: var(--accent-color-1);
}

&__danger {
background: var(--error-color-1);
color: var(--light-inverse);
Expand Down
2 changes: 1 addition & 1 deletion src/components/general/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type HTMLButtonProps = React.DetailedHTMLProps<
HTMLButtonElement
>
type TButtonProps = HTMLButtonProps & {
customType?: 'action-icon' | 'action' | 'danger' | 'primary'
customType?: 'action-icon' | 'action' | 'danger' | 'primary' | 'outline'
size?: 'small' | 'medium'
textVariant?: TextVariant
leftIcon?: React.ReactNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@
&__container {
max-width: 75rem;
width: 100%;

&__form {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 1em;
width: 100%;

.Input {
width: 100%;
}

.Button {
padding-left: 1rem;
padding-right: 1rem;
}

&__buttons {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: 0.5em;
width: 100%;
}
}
}
}

Expand Down
42 changes: 37 additions & 5 deletions src/components/settings/NotificationsSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cn from 'classnames'
import { AnimatePresence } from 'framer-motion'
import { motion } from 'framer-motion'

import Button from '@/components/general/Button'
import NotificationIcon from '@/components/general/Icon/Notification'
import PrivacyIcon from '@/components/general/Icon/Privacy'
import Input from '@/components/general/Input'
Expand All @@ -13,6 +14,7 @@ import W3iContext from '@/contexts/W3iContext/context'
import { useNotificationPermissionState } from '@/utils/hooks/notificationHooks'
import { getDbEchoRegistrations } from '@/utils/idb'
import { notificationsEnabledInBrowser, requireNotifyPermission } from '@/utils/notifications'
import { showSuccessMessageToast } from '@/utils/toasts'

import SettingsHeader from '../SettingsHeader'
import SettingsItem from '../SettingsItem'
Expand All @@ -34,6 +36,9 @@ const getHelperTooltip = () => {
const NotificationsSettings: React.FC = () => {
const { isDevModeEnabled, updateSettings, filterAppDomain } = useContext(SettingsContext)
const { notifyClientProxy } = useContext(W3iContext)
const [domain, setDomain] = useState(filterAppDomain)

const canSave = domain !== filterAppDomain

const notificationsEnabled = useNotificationPermissionState()

Expand All @@ -60,6 +65,17 @@ const NotificationsSettings: React.FC = () => {
}
}

const handleClearDomain = () => {
setDomain('')
updateSettings({ filterAppDomain: '' })
showSuccessMessageToast('Configurations saved')
}

const handleSaveDomain = () => {
updateSettings({ filterAppDomain: domain })
showSuccessMessageToast('Configurations saved')
}

return (
<AnimatePresence>
<motion.div
Expand All @@ -78,11 +94,27 @@ const NotificationsSettings: React.FC = () => {
subtitle="Provide the domain of your app"
className="NotificationsSettings__notifications"
>
<Input
value={filterAppDomain}
placeholder="app.example.com"
onChange={ev => updateSettings({ filterAppDomain: ev.target.value })}
/>
<div className="NotificationsSettings__content__container__form">
<Input
value={domain}
placeholder="app.example.com"
onChange={ev => setDomain(ev.target.value)}
tabIndex={1}
/>
<div className="NotificationsSettings__content__container__form__buttons">
<Button
disabled={domain === ''}
onClick={handleClearDomain}
customType="outline"
tabIndex={3}
>
Clear
</Button>
<Button disabled={!canSave} onClick={handleSaveDomain} tabIndex={2}>
Save
</Button>
</div>
</div>
</SettingsItem>

<div title={getHelperTooltip()}>
Expand Down

1 comment on commit 047faf4

@vercel
Copy link

@vercel vercel bot commented on 047faf4 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.