API & Client - max sizes and max number of files must be greater than 0 - #71

This commit is contained in:
Sam
2021-02-20 16:59:31 +01:00
parent c4e579dd25
commit fbc40385a0
18 changed files with 203 additions and 26 deletions

View File

@ -1,6 +1,7 @@
import FitTrackeeGenericApi from '../fitTrackeeApi'
import { history } from '../index'
import { setError } from './index'
import { generateIds } from '../utils'
import { emptyMessages, setError } from './index'
export const setAppConfig = data => ({
type: 'SET_APP_CONFIG',
@ -12,6 +13,8 @@ export const setAppStats = data => ({
data,
})
const SetAppErrors = messages => ({ type: 'APP_ERRORS', messages })
export const getAppData = target => dispatch =>
FitTrackeeGenericApi.getData(target)
.then(ret => {
@ -27,14 +30,18 @@ export const getAppData = target => dispatch =>
})
.catch(error => dispatch(setError(`application|${error}`)))
export const updateAppConfig = formData => dispatch =>
export const updateAppConfig = formData => dispatch => {
dispatch(emptyMessages())
FitTrackeeGenericApi.updateData('config', formData)
.then(ret => {
if (ret.status === 'success') {
dispatch(setAppConfig(ret.data))
history.push('/admin/application')
} else if (Array.isArray(ret.message)) {
dispatch(SetAppErrors(generateIds(ret.message)))
} else {
dispatch(setError(`application|${ret.message}`))
dispatch(setError(ret.message))
}
})
.catch(error => dispatch(setError(`application|${error}`)))
}

View File

@ -3,11 +3,16 @@ import i18next from 'i18next'
import FitTrackeeApi from '../fitTrackeeApi/index'
import { history } from '../index'
export const emptyMessages = () => ({
type: 'CLEAN_ALL_MESSAGES',
})
export const setData = (target, data) => ({
type: 'SET_DATA',
data,
target,
})
export const setPaginatedData = (target, data, pagination) => ({
type: 'SET_PAGINATED_DATA',
data,
@ -51,7 +56,7 @@ export const getOrUpdateData = (
dispatch(setLoading(false))
return dispatch(setError(`${target}|Incorrect id`))
}
dispatch(setError(''))
dispatch(emptyMessages())
return FitTrackeeApi[action](target, data)
.then(ret => {
if (ret.status === 'success') {

View File

@ -48,13 +48,16 @@ class AdminApplication extends React.Component {
isInEdition,
loadAppConfig,
message,
messages,
onHandleConfigFormSubmit,
t,
} = this.props
const { formData } = this.state
return (
<div>
{message && <Message message={message} t={t} />}
{(message || messages) && (
<Message message={message} messages={messages} t={t} />
)}
{Object.keys(formData).length > 0 && (
<div className="row">
<div className="col-md-12">
@ -209,6 +212,7 @@ class AdminApplication extends React.Component {
export default connect(
state => ({
message: state.message,
messages: state.messages,
}),
dispatch => ({
loadAppConfig: () => {

View File

@ -14,7 +14,10 @@
"Invalid credentials.": "Invalid credentials.",
"Invalid payload.": "Invalid payload.",
"Invalid token. Please log in again.": "Invalid token. Please log in again.",
"Max. files in a zip archive must be greater than 0": "Max. files in a zip archive must be greater than 0",
"Max. size of uploaded files must be greater than 0": "Max. size of uploaded files must be greater than 0",
"Max. size of zip archive must be equal or greater than max. size of uploaded files": "Max. size of zip archive must be equal or greater than max. size of uploaded files",
"Max. size of zip archive must be greater than 0": "Max. size of zip archive must be greater than 0",
"No file part.": "No file part.",
"No picture.": "No picture.",
"No selected file.": "No selected file.",

View File

@ -14,7 +14,10 @@
"Invalid credentials.": "Identifiants invalides.",
"Invalid payload.": "Données incorrectes.",
"Invalid token. Please log in again.": "Jeton invalide. Merci de vous reconnecter.",
"Max. files in a zip archive must be greater than 0": "Le nombre max. de fichiers dans une archive doit être supérieur à 0",
"Max. size of uploaded files must be greater than 0": "La taille max. des fichiers doit être supérieure à 0",
"Max. size of zip archive must be equal or greater than max. size of uploaded files": "La taille max. d'une archive doit être supérieure ou égale à la taille max. d'un fichier",
"Max. size of zip archive must be greater than 0": "La taille max. d'une archive doit être supérieure à 0",
"No file part.": "Pas de fichier fourni.",
"No picture.": "Pas d'image.",
"No selected file.": "Pas de fichier sélectionné.",

View File

@ -108,6 +108,7 @@ const message = (state = initial.message, action) => {
case 'PICTURE_ERROR':
case 'SET_ERROR':
return action.message
case 'CLEAN_ALL_MESSAGES':
case 'LOGOUT':
case 'PROFILE_SUCCESS':
case 'SET_APP_CONFIG':
@ -122,7 +123,9 @@ const message = (state = initial.message, action) => {
const messages = (state = initial.messages, action) => {
switch (action.type) {
case 'AUTH_ERRORS':
case 'APP_ERRORS':
return action.messages
case 'CLEAN_ALL_MESSAGES':
case 'LOGOUT':
case 'PROFILE_SUCCESS':
case '@@router/LOCATION_CHANGE':