Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7c0e052c
Commit
7c0e052c
authored
Dec 06, 2022
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notifications switch: fixes, add toast
parent
d9453168
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
11 deletions
+69
-11
WatchListItem.tsx
ui/watchlist/WatchlistTable/WatchListItem.tsx
+49
-6
WatchListTableItem.tsx
ui/watchlist/WatchlistTable/WatchListTableItem.tsx
+20
-5
No files found.
ui/watchlist/WatchlistTable/WatchListItem.tsx
View file @
7c0e052c
...
...
@@ -4,6 +4,8 @@ import React, { useCallback, useState } from 'react';
import
type
{
TWatchlistItem
}
from
'
types/client/account
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
AccountListItemMobile
from
'
ui/shared/AccountListItemMobile
'
;
import
TableItemActionButtons
from
'
ui/shared/TableItemActionButtons
'
;
...
...
@@ -17,6 +19,7 @@ interface Props {
const
WatchListItem
=
({
item
,
onEditClick
,
onDeleteClick
}:
Props
)
=>
{
const
[
notificationEnabled
,
setNotificationEnabled
]
=
useState
(
item
.
notification_methods
.
email
);
const
[
switchDisabled
,
setSwitchDisabled
]
=
useState
(
false
);
const
onItemEditClick
=
useCallback
(()
=>
{
return
onEditClick
(
item
);
},
[
item
,
onEditClick
]);
...
...
@@ -25,16 +28,49 @@ const WatchListItem = ({ item, onEditClick, onDeleteClick }: Props) => {
return
onDeleteClick
(
item
);
},
[
item
,
onDeleteClick
]);
const
errorToast
=
useToast
();
const
fetch
=
useFetch
();
const
showErrorToast
=
useCallback
(()
=>
{
errorToast
({
position
:
'
top-right
'
,
description
:
'
There has been an error processing your request
'
,
colorScheme
:
'
red
'
,
status
:
'
error
'
,
variant
:
'
subtle
'
,
isClosable
:
true
,
icon
:
null
,
});
},
[
errorToast
]);
const
notificationToast
=
useToast
();
const
showNotificationToast
=
useCallback
((
isOn
:
boolean
)
=>
{
notificationToast
({
position
:
'
top-right
'
,
description
:
isOn
?
'
Email notification is ON
'
:
'
Email notification is OFF
'
,
colorScheme
:
'
green
'
,
status
:
'
success
'
,
variant
:
'
subtle
'
,
title
:
'
Success
'
,
isClosable
:
true
,
icon
:
null
,
});
},
[
notificationToast
]);
const
{
mutate
}
=
useMutation
(()
=>
{
const
data
=
{
...
item
,
notification_methods
:
{
email
:
!
notificationEnabled
}
};
return
fetch
(
`/node-api/account/watchlist/
${
item
.
id
}
`
,
{
method
:
'
PUT
'
,
body
:
JSON
.
stringify
(
data
)
});
setSwitchDisabled
(
true
);
const
body
=
{
...
item
,
notification_methods
:
{
email
:
!
notificationEnabled
}
};
setNotificationEnabled
(
prevState
=>
!
prevState
);
return
fetch
(
`/node-api/account/watchlist/
${
item
.
id
}
`
,
{
method
:
'
PUT
'
,
body
});
},
{
onError
:
()
=>
{
// eslint-disable-next-line no-console
console
.
log
(
'
error
'
);
showErrorToast
();
setNotificationEnabled
(
prevState
=>
!
prevState
);
setSwitchDisabled
(
false
);
},
onSuccess
:
()
=>
{
setNotificationEnabled
(
prevState
=>
!
prevState
);
setSwitchDisabled
(
false
);
showNotificationToast
(
!
notificationEnabled
);
},
});
...
...
@@ -56,7 +92,14 @@ const WatchListItem = ({ item, onEditClick, onDeleteClick }: Props) => {
<
Flex
alignItems=
"center"
justifyContent=
"space-between"
mt=
{
6
}
w=
"100%"
>
<
HStack
spacing=
{
3
}
>
<
Text
fontSize=
"sm"
fontWeight=
{
500
}
>
Email notification
</
Text
>
<
Switch
colorScheme=
"blue"
size=
"md"
isChecked=
{
notificationEnabled
}
onChange=
{
onSwitch
}
aria
-
label=
"Email notification"
/>
<
Switch
colorScheme=
"blue"
size=
"md"
isChecked=
{
notificationEnabled
}
onChange=
{
onSwitch
}
aria
-
label=
"Email notification"
isDisabled=
{
switchDisabled
}
/>
</
HStack
>
<
TableItemActionButtons
onDeleteClick=
{
onItemDeleteClick
}
onEditClick=
{
onItemEditClick
}
/>
</
Flex
>
...
...
ui/watchlist/WatchlistTable/WatchListTableItem.tsx
View file @
7c0e052c
...
...
@@ -33,11 +33,11 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
return
onDeleteClick
(
item
);
},
[
item
,
onDeleteClick
]);
const
t
oast
=
useToast
();
const
errorT
oast
=
useToast
();
const
fetch
=
useFetch
();
const
showToast
=
useCallback
(()
=>
{
t
oast
({
const
show
Error
Toast
=
useCallback
(()
=>
{
errorT
oast
({
position
:
'
top-right
'
,
description
:
'
There has been an error processing your request
'
,
colorScheme
:
'
red
'
,
...
...
@@ -46,7 +46,21 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
isClosable
:
true
,
icon
:
null
,
});
},
[
toast
]);
},
[
errorToast
]);
const
notificationToast
=
useToast
();
const
showNotificationToast
=
useCallback
((
isOn
:
boolean
)
=>
{
notificationToast
({
position
:
'
top-right
'
,
description
:
isOn
?
'
Email notification is ON
'
:
'
Email notification is OFF
'
,
colorScheme
:
'
green
'
,
status
:
'
success
'
,
variant
:
'
subtle
'
,
title
:
'
Success
'
,
isClosable
:
true
,
icon
:
null
,
});
},
[
notificationToast
]);
const
{
mutate
}
=
useMutation
(()
=>
{
setSwitchDisabled
(
true
);
...
...
@@ -55,12 +69,13 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
return
fetch
(
`/node-api/account/watchlist/
${
item
.
id
}
`
,
{
method
:
'
PUT
'
,
body
});
},
{
onError
:
()
=>
{
showToast
();
show
Error
Toast
();
setNotificationEnabled
(
prevState
=>
!
prevState
);
setSwitchDisabled
(
false
);
},
onSuccess
:
()
=>
{
setSwitchDisabled
(
false
);
showNotificationToast
(
!
notificationEnabled
);
},
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment