@@ -23,6 +23,7 @@ import AuthenticatedUserContext from '../Profile/AuthenticatedUserContext';
2323import ShareDialog from './ShareDialog' ;
2424
2525import {
26+ deleteGame ,
2627 getGameUrl ,
2728 updateGame ,
2829 type Game ,
@@ -94,6 +95,7 @@ export const GameCard = ({
9495 editedProperty ,
9596 setEditedProperty ,
9697 ] = React . useState < ?TogglableProperties > ( null ) ;
98+ const [ isDeletingGame , setIsDeletingGame ] = React . useState ( false ) ;
9799
98100 const { getAuthorizationHeader, profile } = React . useContext (
99101 AuthenticatedUserContext
@@ -119,14 +121,62 @@ export const GameCard = ({
119121 } catch ( error ) {
120122 console . error ( `Unable to update property ${ property } ` , error ) ;
121123 showErrorBox ( {
122- message : i18n . _ ( t `Unable to update game.` ) ,
124+ message :
125+ i18n . _ ( t `Unable to update game.` ) +
126+ ' ' +
127+ i18n . _ ( t `Verify your internet connection or try again later.` ) ,
123128 rawError : error ,
124129 errorId : 'game-dashboard-update-game-error' ,
125130 } ) ;
126131 }
127132 setEditedProperty ( null ) ;
128133 } ;
129134
135+ const unregisterGame = async ( i18n : I18nType ) => {
136+ const answer = Window . showConfirmDialog (
137+ i18n . _ ( t `Are you sure you want to unregister this game?` ) +
138+ '\n\n' +
139+ i18n . _ (
140+ t `It will disappear from your games dashboard and you won't get access to analytics, unless you register it again.`
141+ )
142+ ) ;
143+ if ( ! answer ) return ;
144+
145+ if ( ! profile ) return ;
146+ const { id } = profile ;
147+ setIsDeletingGame ( true ) ;
148+
149+ try {
150+ await deleteGame ( getAuthorizationHeader , id , game . id ) ;
151+ await onUpdateGame ( ) ;
152+ } catch ( error ) {
153+ console . error ( 'Unable to delete the game:' , error ) ;
154+ if (
155+ error . response &&
156+ error . response . data &&
157+ error . response . data . code === 'game-deletion/leaderboards-exist'
158+ ) {
159+ showErrorBox ( {
160+ message : i18n . _ (
161+ t `You cannot unregister a game that has active leaderboards. To delete them, go in the Leaderboards tab, and delete them one by one.`
162+ ) ,
163+ rawError : error ,
164+ errorId : 'game-dashboard-unregister-game-active-leaderboards-error' ,
165+ } ) ;
166+ } else {
167+ showErrorBox ( {
168+ message :
169+ i18n . _ ( t `Unable to delete the game.` ) +
170+ ' ' +
171+ i18n . _ ( t `Verify your internet connection or try again later.` ) ,
172+ rawError : error ,
173+ errorId : 'game-dashboard-unregister-game-active-leaderboards-error' ,
174+ } ) ;
175+ }
176+ setIsDeletingGame ( false ) ;
177+ }
178+ } ;
179+
130180 return (
131181 < I18n >
132182 { ( { i18n } ) => (
@@ -136,31 +186,38 @@ export const GameCard = ({
136186 cardCornerAction = {
137187 < ElementWithMenu
138188 element = {
139- < IconButton size = "small" >
189+ < IconButton size = "small" disabled = { isDeletingGame } >
140190 < MoreVert />
141191 </ IconButton >
142192 }
143193 buildMenuTemplate = { ( i18n : I18nType ) => [
144194 {
145- label : i18n . _ ( t `Open details` ) ,
195+ label : i18n . _ ( t `Game details` ) ,
146196 click : ( ) => onOpenGameManager ( 'details' ) ,
147197 } ,
148198 {
149- label : i18n . _ ( t `See builds` ) ,
199+ label : i18n . _ ( t `Game builds` ) ,
150200 click : ( ) => onOpenGameManager ( 'builds' ) ,
151201 } ,
152202 {
153- label : i18n . _ ( t `See feedbacks` ) ,
203+ label : i18n . _ ( t `Game feedbacks` ) ,
154204 click : ( ) => onOpenGameManager ( 'feedback' ) ,
155205 } ,
156206 {
157- label : i18n . _ ( t `Open analytics` ) ,
207+ label : i18n . _ ( t `Game analytics` ) ,
158208 click : ( ) => onOpenGameManager ( 'analytics' ) ,
159209 } ,
160210 {
161- label : i18n . _ ( t `Manage leaderboards` ) ,
211+ label : i18n . _ ( t `Game leaderboards` ) ,
162212 click : ( ) => onOpenGameManager ( 'leaderboards' ) ,
163213 } ,
214+ { type : 'separator' } ,
215+ {
216+ label : i18n . _ ( t `Unregister game` ) ,
217+ click : ( ) => {
218+ unregisterGame ( i18n ) ;
219+ } ,
220+ } ,
164221 ] }
165222 />
166223 }
@@ -215,22 +272,22 @@ export const GameCard = ({
215272 noColumnMargin
216273 >
217274 < FlatButton
218- label = { < Trans > Access feedback </ Trans > }
219- onClick = { ( ) => onOpenGameManager ( 'feedback ' ) }
220- disabled = { ! game . publicWebBuildId }
275+ label = { < Trans > Manage game </ Trans > }
276+ onClick = { ( ) => onOpenGameManager ( 'details ' ) }
277+ disabled = { ! game . publicWebBuildId || isDeletingGame }
221278 />
222279 < LineStackLayout noMargin >
223280 < Column noMargin expand >
224281 < RaisedButton
225282 label = { < Trans > Open in browser</ Trans > }
226283 onClick = { openGameUrl }
227284 primary
228- disabled = { ! game . publicWebBuildId }
285+ disabled = { ! game . publicWebBuildId || isDeletingGame }
229286 />
230287 </ Column >
231288 < IconButton
232289 size = "small"
233- disabled = { ! game . publicWebBuildId }
290+ disabled = { ! game . publicWebBuildId || isDeletingGame }
234291 onClick = { ( ) => setShowShareDialog ( true ) }
235292 tooltip = { t `Share` }
236293 >
@@ -248,7 +305,9 @@ export const GameCard = ({
248305 } }
249306 toggled = { ! ! game . discoverable }
250307 label = { < Trans > Make discoverable on Liluo.io</ Trans > }
251- disabled = { editedProperty === 'discoverable' }
308+ disabled = {
309+ editedProperty === 'discoverable' || isDeletingGame
310+ }
252311 />
253312 < Toggle
254313 labelPosition = "left"
@@ -263,7 +322,9 @@ export const GameCard = ({
263322 label = {
264323 < Trans > Show feedback banner on Liluo.io game page</ Trans >
265324 }
266- disabled = { editedProperty === 'acceptsGameComments' }
325+ disabled = {
326+ editedProperty === 'acceptsGameComments' || isDeletingGame
327+ }
267328 />
268329 < Toggle
269330 labelPosition = "left"
@@ -276,7 +337,10 @@ export const GameCard = ({
276337 } }
277338 toggled = { ! ! game . acceptsBuildComments }
278339 label = { < Trans > Ask for feedback on all build pages</ Trans > }
279- disabled = { editedProperty === 'acceptsBuildComments' }
340+ disabled = {
341+ editedProperty === 'acceptsBuildComments' ||
342+ isDeletingGame
343+ }
280344 />
281345 </ Column >
282346 </ Column >
0 commit comments