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
fd0fbe8a
Unverified
Commit
fd0fbe8a
authored
Sep 05, 2022
by
tom goriunov
Committed by
GitHub
Sep 05, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #124 from blockscout/switch-fix
handle switch error
parents
349f2e75
8b68dfdc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
5 deletions
+33
-5
WatchListTableItem.tsx
ui/watchlist/WatchlistTable/WatchListTableItem.tsx
+33
-5
No files found.
ui/watchlist/WatchlistTable/WatchListTableItem.tsx
View file @
fd0fbe8a
...
...
@@ -9,6 +9,8 @@ import React, { useCallback, useState } from 'react';
import
type
{
TWatchlistItem
}
from
'
types/client/account
'
;
import
fetch
from
'
lib/client/fetch
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
TableItemActionButtons
from
'
ui/shared/TableItemActionButtons
'
;
import
TruncatedTextTooltip
from
'
ui/shared/TruncatedTextTooltip
'
;
...
...
@@ -22,6 +24,7 @@ interface Props {
const
WatchlistTableItem
=
({
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
]);
...
...
@@ -30,16 +33,33 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
return
onDeleteClick
(
item
);
},
[
item
,
onDeleteClick
]);
const
toast
=
useToast
();
const
showToast
=
useCallback
(()
=>
{
toast
({
position
:
'
top-right
'
,
description
:
'
There has been an error processing your request
'
,
colorScheme
:
'
red
'
,
status
:
'
error
'
,
variant
:
'
subtle
'
,
isClosable
:
true
,
icon
:
null
,
});
},
[
toast
]);
const
{
mutate
}
=
useMutation
(()
=>
{
setSwitchDisabled
(
true
);
const
data
=
{
...
item
,
notification_methods
:
{
email
:
!
notificationEnabled
}
};
return
fetch
(
`/api/account/watchlist/
${
item
.
id
}
`
,
{
method
:
'
PUT
'
,
body
:
JSON
.
stringify
(
data
)
});
setNotificationEnabled
(
prevState
=>
!
prevState
);
return
fetch
(
`/api/account1/watchlist/
${
item
.
id
}
`
,
{
method
:
'
PUT
'
,
body
:
JSON
.
stringify
(
data
)
});
},
{
onError
:
()
=>
{
// eslint-disable-next-line no-console
console
.
log
(
'
error
'
);
showToast
();
setNotificationEnabled
(
prevState
=>
!
prevState
);
setSwitchDisabled
(
false
);
},
onSuccess
:
()
=>
{
set
NotificationEnabled
(
prevState
=>
!
prevStat
e
);
set
SwitchDisabled
(
fals
e
);
},
});
...
...
@@ -57,7 +77,15 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
</
Tag
>
</
TruncatedTextTooltip
>
</
Td
>
<
Td
><
Switch
colorScheme=
"blue"
size=
"md"
isChecked=
{
notificationEnabled
}
onChange=
{
onSwitch
}
/></
Td
>
<
Td
>
<
Switch
colorScheme=
"blue"
size=
"md"
isChecked=
{
notificationEnabled
}
onChange=
{
onSwitch
}
isDisabled=
{
switchDisabled
}
/>
</
Td
>
<
Td
>
<
TableItemActionButtons
onDeleteClick=
{
onItemDeleteClick
}
onEditClick=
{
onItemEditClick
}
/>
</
Td
>
...
...
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