Update validation, dll Hospital-Portal
This commit is contained in:
38
frontend/hospital-portal/src/contexts/LanguageContext.tsx
Normal file
38
frontend/hospital-portal/src/contexts/LanguageContext.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import React, { createContext, useState, useEffect, useRef } from 'react';
|
||||
import getLocalizedData from '../LocalizationUtil';
|
||||
export const LanguageContext = createContext();
|
||||
|
||||
export const LanguageProvider = ({ children }) => {
|
||||
const [currentLocale, setCurrentLocale] = useState(localStorage.getItem('currentLocale') ? localStorage.getItem('currentLocale') : 'id-ID');
|
||||
const [localeData, setLocaleData] = useState('id');
|
||||
const cancelToken = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const token = { cancelled: false };
|
||||
cancelToken.current = token;
|
||||
|
||||
try {
|
||||
const data = await getLocalizedData(currentLocale);
|
||||
if (!cancelToken.current.cancelled) {
|
||||
setLocaleData(data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching localized data:', error);
|
||||
// Tangani kesalahan jika diperlukan
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
|
||||
return () => {
|
||||
cancelToken.current.cancelled = true;
|
||||
};
|
||||
}, [currentLocale]);
|
||||
|
||||
return (
|
||||
<LanguageContext.Provider value={{ currentLocale, setCurrentLocale, localeData }}>
|
||||
{children}
|
||||
</LanguageContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -122,10 +122,18 @@ function AuthProvider({ children }: AuthProviderProps) {
|
||||
initialize();
|
||||
}, []);
|
||||
|
||||
const headers = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type' : 'application/json',
|
||||
'Accept-Language': (localStorage.getItem('currentLocale') ? localStorage.getItem('currentLocale') : 'id-ID'),
|
||||
},
|
||||
};
|
||||
|
||||
const login = async (email: string, password: string) => axios
|
||||
.post('/login', { email, password })
|
||||
.post('/login', { email, password }, headers)
|
||||
.then((response) => {
|
||||
const { user, token } = response.data;
|
||||
const { user, token } = response.data.data;
|
||||
setSession(token);
|
||||
|
||||
dispatch({
|
||||
|
||||
Reference in New Issue
Block a user