11import { createSlice , createAsyncThunk , PayloadAction } from "@reduxjs/toolkit"
22import { message } from "antd"
33
4- import { searchRepo , updateRepo , deactivateRepo , lockRepo , unlockRepo } from "../apis"
4+ import { searchRepo , updateRepo , deactivateRepo } from "../apis"
55import { Repo , RequestStatus , HttpForbiddenError } from "../models"
66
77interface RepoSettingsState {
@@ -43,10 +43,9 @@ export const save = createAsyncThunk<Repo, void, { state: {repoSettings: RepoSet
4343 return nr
4444 } catch ( e ) {
4545 if ( e instanceof HttpForbiddenError ) {
46- message . error ( "Only admin permission can update." , 3 )
47- } else {
48- message . error ( "It has failed to save." , 3 )
49- }
46+ message . warn ( "Only admin permission can update." , 3 )
47+ }
48+
5049 return rejectWithValue ( e )
5150 }
5251 } ,
@@ -64,52 +63,9 @@ export const deactivate = createAsyncThunk<Repo, void, { state: {repoSettings: R
6463 return nr
6564 } catch ( e ) {
6665 if ( e instanceof HttpForbiddenError ) {
67- message . error ( "Only admin permission can deactivate." , 3 )
68- } else {
69- message . error ( "It has failed to save." , 3 )
70- }
71- return rejectWithValue ( e )
72- }
73- } ,
74- )
75-
76- export const lock = createAsyncThunk < Repo , void , { state : { repoSettings : RepoSettingsState } } > (
77- 'repoSettings/lock' ,
78- async ( _ , { getState, rejectWithValue } ) => {
79- const { repo } = getState ( ) . repoSettings
80- if ( ! repo ) throw new Error ( "There is no repo." )
81-
82- try {
83- const ret = await lockRepo ( repo )
84- message . info ( "Lock the repository successfully." , 3 )
85- return ret
86- } catch ( e ) {
87- if ( e instanceof HttpForbiddenError ) {
88- message . error ( "Only admin permission can lock the repository." , 3 )
89- } else {
90- message . error ( "It has failed to lock." , 3 )
91- }
92- return rejectWithValue ( e )
93- }
94- } ,
95- )
96-
97- export const unlock = createAsyncThunk < Repo , void , { state : { repoSettings : RepoSettingsState } } > (
98- 'repoSettings/unlock' ,
99- async ( _ , { getState, rejectWithValue } ) => {
100- const { repo } = getState ( ) . repoSettings
101- if ( ! repo ) throw new Error ( "There is no repo." )
66+ message . warn ( "Only admin permission can deactivate." , 3 )
67+ }
10268
103- try {
104- const ret = await unlockRepo ( repo )
105- message . info ( "Unlock the repository successfully." , 3 )
106- return ret
107- } catch ( e ) {
108- if ( e instanceof HttpForbiddenError ) {
109- message . error ( "Only admin permission can unlock the repository." , 3 )
110- } else {
111- message . error ( "It has failed to unlock." , 3 )
112- }
11369 return rejectWithValue ( e )
11470 }
11571 } ,
@@ -158,11 +114,5 @@ export const repoSettingsSlice = createSlice({
158114 . addCase ( deactivate . rejected , ( state ) => {
159115 state . deactivating = RequestStatus . Idle
160116 } )
161- . addCase ( lock . fulfilled , ( state , action ) => {
162- state . repo = action . payload
163- } )
164- . addCase ( unlock . fulfilled , ( state , action ) => {
165- state . repo = action . payload
166- } )
167117 }
168118} )
0 commit comments