focalboard/webapp/src/store/globalTemplates.ts
Miguel de la Cruz fa6de94070
Adds limits implementation to the server (#3213)
* Adds limits implementation to the server

* Add test for deleted boards on active card count
2022-06-15 12:17:44 +02:00

36 lines
1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {createSlice, createAsyncThunk} from '@reduxjs/toolkit'
import {default as client} from '../octoClient'
import {Board} from '../blocks/board'
import {Constants} from "../constants"
import {RootState} from './index'
export const fetchGlobalTemplates = createAsyncThunk(
'globalTemplates/fetch',
async () => {
const templates = await client.getTeamTemplates(Constants.globalTeamId)
return templates.sort((a, b) => a.title.localeCompare(b.title))
},
)
const globalTemplatesSlice = createSlice({
name: 'globalTemplates',
initialState: {value: []} as {value: Board[]},
reducers: {},
extraReducers: (builder) => {
builder.addCase(fetchGlobalTemplates.fulfilled, (state, action) => {
state.value = action.payload || []
})
},
})
export const {reducer} = globalTemplatesSlice
export function getGlobalTemplates(state: RootState): Board[] {
return state.globalTemplates.value
}