Commit f620bab7 by asranov0003

feat: render and settimezone

parent b1a872bd
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import "./Settings.css"; import "./Settings.css";
import { useLanguage } from "../../contexts/LanguageContext/useLanguage"; import { useLanguage } from "../../contexts/LanguageContext/useLanguage";
import CSelect from "../../components/CSelect"; import CSelect from "../../components/CSelect";
...@@ -19,10 +19,15 @@ import CModal from "../../components/CModal"; ...@@ -19,10 +19,15 @@ import CModal from "../../components/CModal";
import CButton from "../../components/CButton"; import CButton from "../../components/CButton";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import CInput from "../../components/CInput"; import CInput from "../../components/CInput";
import { checkPassword } from "../../stores/slices/accountSlice"; import { checkPassword, setTimezone } from "../../stores/slices/accountSlice";
import { TIME_ZONES } from "../../constants/timezones";
const Settings: React.FC = () => { const Settings: React.FC = () => {
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [selectedTimezone, setSelectedTimezone] = useState({
ianaId: "Asia/Tashkent",
name: "(UTC+05:00) Ashgabat, Tashkent",
});
const [isOpenLogoutModal, setIsOpenLogoutModal] = useState(false); const [isOpenLogoutModal, setIsOpenLogoutModal] = useState(false);
const [isOpenDeleteAccountModal, setIsOpenDeleteAccountModal] = const [isOpenDeleteAccountModal, setIsOpenDeleteAccountModal] =
useState(false); useState(false);
...@@ -31,6 +36,7 @@ const Settings: React.FC = () => { ...@@ -31,6 +36,7 @@ const Settings: React.FC = () => {
const { isCheckPasswordLoading, errorCheckPassword } = useAppSelector( const { isCheckPasswordLoading, errorCheckPassword } = useAppSelector(
(state: RootState) => state.account (state: RootState) => state.account
); );
const { session } = useAppSelector((state: RootState) => state.account);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const toggleLogoutModal = () => { const toggleLogoutModal = () => {
...@@ -41,6 +47,15 @@ const Settings: React.FC = () => { ...@@ -41,6 +47,15 @@ const Settings: React.FC = () => {
setIsOpenDeleteAccountModal((prev) => !prev); setIsOpenDeleteAccountModal((prev) => !prev);
}; };
useEffect(() => {
if (session.timeZoneStr) {
const tz = TIME_ZONES.find((tz) => tz.ianaId === session.timeZoneStr);
if (tz) {
setSelectedTimezone(tz);
}
}
}, [session]);
return ( return (
<div className="settings"> <div className="settings">
<h3 className="settings__title">{t("settings.title")}</h3> <h3 className="settings__title">{t("settings.title")}</h3>
...@@ -88,6 +103,21 @@ const Settings: React.FC = () => { ...@@ -88,6 +103,21 @@ const Settings: React.FC = () => {
]} ]}
/> />
<CSelect
value={selectedTimezone.ianaId}
options={TIME_ZONES.map((tz) => ({
label: tz.name,
value: tz.ianaId,
}))}
onChange={(ianaId: string) => {
const tz = TIME_ZONES.find((tz) => tz.ianaId === ianaId);
if (tz) {
setSelectedTimezone(tz);
dispatch(setTimezone({ zone: tz.ianaId, offset: tz.offset }));
}
}}
/>
<h3>{t("settings.account")}</h3> <h3>{t("settings.account")}</h3>
<div <div
......
...@@ -6,6 +6,8 @@ interface ISession { ...@@ -6,6 +6,8 @@ interface ISession {
login: string; login: string;
emailVerified: boolean; emailVerified: boolean;
subDateEnd: string; subDateEnd: string;
paid: boolean;
timeZoneStr: string;
} }
interface IAccountState { interface IAccountState {
...@@ -20,6 +22,8 @@ const initialState: IAccountState = { ...@@ -20,6 +22,8 @@ const initialState: IAccountState = {
login: "", login: "",
emailVerified: false, emailVerified: false,
subDateEnd: "", subDateEnd: "",
paid: true,
timeZoneStr: "",
}, },
loading: false, loading: false,
isCheckPasswordLoading: false, isCheckPasswordLoading: false,
...@@ -80,6 +84,28 @@ export const checkPassword = createAsyncThunk( ...@@ -80,6 +84,28 @@ export const checkPassword = createAsyncThunk(
} }
); );
export const setTimezone = createAsyncThunk(
"account/setTimezone",
async (
{ zone, offset }: { zone: string; offset: number },
{ rejectWithValue }
) => {
try {
const response = await sendRpcRequest("account.setTimeZone", {
zone,
offset,
});
return response;
} catch (error) {
if (typeof error === "object" && error !== null && "message" in error) {
return rejectWithValue((error as { message: string }).message);
}
return rejectWithValue("Unknown error occurred");
}
}
);
const accountSlice = createSlice({ const accountSlice = createSlice({
name: "account", name: "account",
initialState, initialState,
...@@ -107,6 +133,16 @@ const accountSlice = createSlice({ ...@@ -107,6 +133,16 @@ const accountSlice = createSlice({
.addCase(checkPassword.rejected, (state, action) => { .addCase(checkPassword.rejected, (state, action) => {
state.isCheckPasswordLoading = false; state.isCheckPasswordLoading = false;
state.errorCheckPassword = action.payload as string; state.errorCheckPassword = action.payload as string;
})
.addCase(setTimezone.pending, (state) => {
state.loading = true;
})
.addCase(setTimezone.fulfilled, (state) => {
state.loading = false;
})
.addCase(setTimezone.rejected, (state) => {
state.loading = false;
}); });
}, },
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment