Fix EkriTeks and adapt to new properties
This commit is contained in:
@@ -23,6 +23,8 @@ import {
|
|||||||
import MuiAlert from '@mui/material/Alert'
|
import MuiAlert from '@mui/material/Alert'
|
||||||
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'
|
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'
|
||||||
|
|
||||||
|
import {jwennAnTeks} from '../../lib/oki-api'
|
||||||
|
|
||||||
import AjouteTradiksyon from './ajoute-tradiksyon'
|
import AjouteTradiksyon from './ajoute-tradiksyon'
|
||||||
|
|
||||||
const PREFIX = 'EkriTeks'
|
const PREFIX = 'EkriTeks'
|
||||||
@@ -108,7 +110,7 @@ function EkriTeks({canAutoTranslate, selectedTeks, setSelectedTeks}) {
|
|||||||
setError('')
|
setError('')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const {awtis, tit, transkripsyon} = teksEkri
|
const {awtis, tit, transkripsyon} = teksEkri
|
||||||
const {fr, en, es, de, it} = tradiksyon
|
const {fr, en, es, de, it} = tradiksyon
|
||||||
@@ -126,81 +128,85 @@ function EkriTeks({canAutoTranslate, selectedTeks, setSelectedTeks}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (currentTeksId) {
|
if (currentTeksId) {
|
||||||
axios.get(`${API_URL}/teks/${currentTeksId}?_publicationState=preview&_where[published_at_null]=true`)
|
try {
|
||||||
.then(awtisResponse => {
|
const teks = await jwennAnTeks(currentTeksId, jwt)
|
||||||
if (awtisResponse.data.user.id !== user.id) {
|
const teksResponse = await axios.put(`${API_URL}/paroles/${currentTeksId}`, {
|
||||||
setLoading(false)
|
data: {
|
||||||
return setError({message: 'Opération non autorisée'})
|
id: teks.id,
|
||||||
|
titre: tit,
|
||||||
|
transcription: transkripsyon,
|
||||||
|
traductions: {
|
||||||
|
francais: fr === '' ? null : fr,
|
||||||
|
anglais: en === '' ? null : en,
|
||||||
|
espagnol: es === '' ? null : es,
|
||||||
|
allemand: de === '' ? null : de,
|
||||||
|
italien: it === '' ? null : it
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
email: user.email
|
||||||
|
},
|
||||||
|
artistes: teks.artistes.map(({id}) => id),
|
||||||
|
traductionAuto: tradiksyonOtomatik
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
|
||||||
axios.put(`${API_URL}/teks/${currentTeksId}`, {
|
const {data} = teksResponse
|
||||||
tit,
|
setSuccess(`Le texte "${data.tit}" a été modifié avec succès. Il apparaîtra sur le site après validation.`)
|
||||||
transkripsyon,
|
setLoading(false)
|
||||||
tradiksyon: {
|
} catch (error) {
|
||||||
francais: fr === '' ? null : fr,
|
setError(error?.response?.data)
|
||||||
english: en === '' ? null : en,
|
setLoading(false)
|
||||||
espagnol: es === '' ? null : es,
|
}
|
||||||
deutsch: de === '' ? null : de,
|
|
||||||
italiano: it === '' ? null : it
|
|
||||||
},
|
|
||||||
user,
|
|
||||||
awtis: awtisResponse.data.awtis.map(id => id),
|
|
||||||
tradiksyonOtomatik
|
|
||||||
}, {
|
|
||||||
headers
|
|
||||||
})
|
|
||||||
.then(teksResponse => {
|
|
||||||
const {data} = teksResponse
|
|
||||||
setSuccess(`Le texte "${data.tit}" a été modifié avec succès. Il apparaîtra sur le site après validation.`)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
setError(error)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
setError(error)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
axios.post(`${API_URL}/awtis`, {
|
try {
|
||||||
alias: awtis,
|
const artiste = await axios.post(`${API_URL}/artistes`, {
|
||||||
user
|
data: {
|
||||||
}, {
|
alias: awtis,
|
||||||
headers
|
user: {
|
||||||
})
|
id: user.id,
|
||||||
.then(awtisResponse => {
|
username: user.username,
|
||||||
axios.post(`${API_URL}/teks`, {
|
email: user.email
|
||||||
tit,
|
}
|
||||||
transkripsyon,
|
}
|
||||||
tradiksyon: {
|
}, {
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
|
||||||
|
const parole = await axios.post(`${API_URL}/paroles`, {
|
||||||
|
data: {
|
||||||
|
titre: tit,
|
||||||
|
transcription: transkripsyon,
|
||||||
|
traductions: {
|
||||||
francais: fr === '' ? null : fr,
|
francais: fr === '' ? null : fr,
|
||||||
english: en === '' ? null : en,
|
anglais: en === '' ? null : en,
|
||||||
espagnol: es === '' ? null : es,
|
espagnol: es === '' ? null : es,
|
||||||
deutsch: de === '' ? null : de,
|
allemand: de === '' ? null : de,
|
||||||
italiano: it === '' ? null : it
|
italien: it === '' ? null : it
|
||||||
},
|
},
|
||||||
user,
|
user: {
|
||||||
awtis: [awtisResponse.data.id],
|
id: user.id,
|
||||||
tradiksyonOtomatik
|
username: user.username,
|
||||||
}, {
|
email: user.email
|
||||||
headers
|
},
|
||||||
})
|
artistes: [artiste.data.id],
|
||||||
.then(teksResponse => {
|
traductionAuto: tradiksyonOtomatik
|
||||||
const {data} = teksResponse
|
}
|
||||||
setSuccess(`Le texte "${data.tit}" a été soumis avec succès. Il apparaîtra sur le site après validation.`)
|
}, {
|
||||||
setLoading(false)
|
headers
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
setError(error)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
setError(error)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const {data} = parole
|
||||||
|
|
||||||
|
setSuccess(`Le texte "${data.titre}" a été soumis avec succès. Il apparaîtra sur le site après validation.`)
|
||||||
|
setLoading(false)
|
||||||
|
} catch (error) {
|
||||||
|
setError(error?.response?.data)
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,39 +236,38 @@ function EkriTeks({canAutoTranslate, selectedTeks, setSelectedTeks}) {
|
|||||||
setTradiksyonOtomatik(false)
|
setTradiksyonOtomatik(false)
|
||||||
setCurrentTeksId(selectedTeks.id)
|
setCurrentTeksId(selectedTeks.id)
|
||||||
setTeksEkri({
|
setTeksEkri({
|
||||||
awtis: new Intl.ListFormat('fr').format(selectedTeks.awtis.map(({alias}) => alias)),
|
awtis: new Intl.ListFormat('fr').format(selectedTeks.artistes.map(({alias}) => alias)),
|
||||||
tit: selectedTeks.tit,
|
tit: selectedTeks.titre,
|
||||||
transkripsyon: selectedTeks.transkripsyon
|
transkripsyon: selectedTeks.transcription
|
||||||
})
|
})
|
||||||
setTradiksyon({
|
setTradiksyon({
|
||||||
fr: selectedTeks.tradiksyon.francais || '',
|
fr: selectedTeks?.traductions?.francais || '',
|
||||||
en: selectedTeks.tradiksyon.english || '',
|
en: selectedTeks?.traductions?.anglais || '',
|
||||||
es: selectedTeks.tradiksyon.espagnol || '',
|
es: selectedTeks?.traductions?.espagnol || '',
|
||||||
de: selectedTeks.tradiksyon.deutsch || '',
|
de: selectedTeks?.traductions?.allemand || '',
|
||||||
it: selectedTeks.tradiksyon.italiano || ''
|
it: selectedTeks?.traductions?.italien || ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const jennLangId = () => {
|
const jennLangId = () => {
|
||||||
const ids = []
|
const ids = []
|
||||||
const {francais, english, espagnol, deutsch, italiano} = selectedTeks.tradiksyon
|
|
||||||
|
|
||||||
if (francais) {
|
if (selectedTeks?.traductions?.francais) {
|
||||||
ids.push('fr')
|
ids.push('fr')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (english) {
|
if (selectedTeks?.traductions?.anglais) {
|
||||||
ids.push('en')
|
ids.push('en')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (espagnol) {
|
if (selectedTeks?.traductions?.espagnol) {
|
||||||
ids.push('es')
|
ids.push('es')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deutsch) {
|
if (selectedTeks?.traductions?.allemand) {
|
||||||
ids.push('de')
|
ids.push('de')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (italiano) {
|
if (selectedTeks?.traductions?.italien) {
|
||||||
ids.push('it')
|
ids.push('it')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +374,7 @@ function EkriTeks({canAutoTranslate, selectedTeks, setSelectedTeks}) {
|
|||||||
</form>
|
</form>
|
||||||
<AjouteTradiksyon
|
<AjouteTradiksyon
|
||||||
showSwitch={Boolean(canAutoTranslate) && Boolean(!currentTeksId)}
|
showSwitch={Boolean(canAutoTranslate) && Boolean(!currentTeksId)}
|
||||||
disableSwitch={tradiksyon.fr === ''}
|
disableSwitch={tradiksyon.fr === '' || tradiksyon.en !== '' || tradiksyon.es !== '' || tradiksyon.de !== '' || tradiksyon.it !== ''}
|
||||||
tradiksyonOtomatik={tradiksyonOtomatik}
|
tradiksyonOtomatik={tradiksyonOtomatik}
|
||||||
setTradiksyonOtomatik={setTradiksyonOtomatik}
|
setTradiksyonOtomatik={setTradiksyonOtomatik}
|
||||||
chwaLang={kiChawLang}
|
chwaLang={kiChawLang}
|
||||||
@@ -410,9 +415,9 @@ function EkriTeks({canAutoTranslate, selectedTeks, setSelectedTeks}) {
|
|||||||
</Snackbar>
|
</Snackbar>
|
||||||
)}
|
)}
|
||||||
{error && (
|
{error && (
|
||||||
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
|
<Snackbar open={open} autoHideDuration={10_000} onClose={handleClose}>
|
||||||
<Alert severity='error' onClose={handleClose}>
|
<Alert severity='error' onClose={handleClose}>
|
||||||
<strong>Une erreur s’est produite</strong> : <i>{error.message}</i>
|
<strong>Une erreur s’est produite</strong> : <i>{error?.error?.message}</i>
|
||||||
</Alert>
|
</Alert>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user