file renamed

This commit is contained in:
Dobromir Popov
2024-04-28 23:45:43 +03:00
parent 57be4d0e88
commit 8d49f93bec

View File

@ -0,0 +1,58 @@
import axiosInstance from '../../../src/axiosSecure';
import common from '../../../src/helpers/common';
import { useState, useEffect } from 'react';
import { Availability, UserRole } from "@prisma/client";
import ProtectedRoute, { serverSideAuth } from "../../../components/protectedRoute";
const AdminTranslations = () => {
const [translations, setTranslations] = useState({});
const [locale, setLocale] = useState('en');
useEffect(() => {
console.log("Current locale:", locale, "Fetching translations...");
axiosInstance.get(`/api/translations/${locale}`).then(res => setTranslations(res.data));
}, [locale]);
const handleSave = () => {
axiosInstance.post(`/api/translations/${locale}`, translations).then(res => {
if (res.data.status === 'Updated') {
alert('Translations updated!');
}
});
};
const handleChange = (key, value) => {
setTranslations(prev => ({ ...prev, [key]: value }));
};
return (
<>
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER]}>
<div>
<h1>Edit Translations</h1>
<select onChange={e => setLocale(e.target.value)} value={locale}>
<option value="bg">BG</option>
<option value="en">English</option>
<option value="ru">RU</option>
{/* Add more options as needed */}
</select>
{Object.keys(translations).map(key => (
<div key={key}>
<label>{key}:</label>
<input
type="text"
value={translations[key]}
onChange={e => handleChange(key, e.target.value)}
/>
</div>
))}
<button onClick={handleSave}>Save Changes</button>
</div>
</ProtectedRoute>
</>
);
};
export default AdminTranslations;