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
3d44ca80
Commit
3d44ca80
authored
Sep 02, 2022
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle switch error
parent
32d9cf05
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 @
3d44ca80
...
@@ -10,6 +10,8 @@ import React, { useCallback, useState } from 'react';
...
@@ -10,6 +10,8 @@ import React, { useCallback, useState } from 'react';
import
type
{
TWatchlistItem
}
from
'
types/client/account
'
;
import
type
{
TWatchlistItem
}
from
'
types/client/account
'
;
import
fetch
from
'
lib/client/fetch
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
DeleteButton
from
'
ui/shared/DeleteButton
'
;
import
DeleteButton
from
'
ui/shared/DeleteButton
'
;
import
EditButton
from
'
ui/shared/EditButton
'
;
import
EditButton
from
'
ui/shared/EditButton
'
;
import
TruncatedTextTooltip
from
'
ui/shared/TruncatedTextTooltip
'
;
import
TruncatedTextTooltip
from
'
ui/shared/TruncatedTextTooltip
'
;
...
@@ -24,6 +26,7 @@ interface Props {
...
@@ -24,6 +26,7 @@ interface Props {
const
WatchlistTableItem
=
({
item
,
onEditClick
,
onDeleteClick
}:
Props
)
=>
{
const
WatchlistTableItem
=
({
item
,
onEditClick
,
onDeleteClick
}:
Props
)
=>
{
const
[
notificationEnabled
,
setNotificationEnabled
]
=
useState
(
item
.
notification_methods
.
email
);
const
[
notificationEnabled
,
setNotificationEnabled
]
=
useState
(
item
.
notification_methods
.
email
);
const
[
switchDisabled
,
setSwitchDisabled
]
=
useState
(
false
);
const
onItemEditClick
=
useCallback
(()
=>
{
const
onItemEditClick
=
useCallback
(()
=>
{
return
onEditClick
(
item
);
return
onEditClick
(
item
);
},
[
item
,
onEditClick
]);
},
[
item
,
onEditClick
]);
...
@@ -32,16 +35,33 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
...
@@ -32,16 +35,33 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
return
onDeleteClick
(
item
);
return
onDeleteClick
(
item
);
},
[
item
,
onDeleteClick
]);
},
[
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
(()
=>
{
const
{
mutate
}
=
useMutation
(()
=>
{
setSwitchDisabled
(
true
);
const
data
=
{
...
item
,
notification_methods
:
{
email
:
!
notificationEnabled
}
};
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
:
()
=>
{
onError
:
()
=>
{
// eslint-disable-next-line no-console
showToast
();
console
.
log
(
'
error
'
);
setNotificationEnabled
(
prevState
=>
!
prevState
);
setSwitchDisabled
(
false
);
},
},
onSuccess
:
()
=>
{
onSuccess
:
()
=>
{
set
NotificationEnabled
(
prevState
=>
!
prevStat
e
);
set
SwitchDisabled
(
fals
e
);
},
},
});
});
...
@@ -59,7 +79,15 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
...
@@ -59,7 +79,15 @@ const WatchlistTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
</
Tag
>
</
Tag
>
</
TruncatedTextTooltip
>
</
TruncatedTextTooltip
>
</
Td
>
</
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
>
<
Td
>
<
HStack
spacing=
{
6
}
>
<
HStack
spacing=
{
6
}
>
<
EditButton
onClick=
{
onItemEditClick
}
/>
<
EditButton
onClick=
{
onItemEditClick
}
/>
...
...
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