chore: move api to api folder and seperate the types into another file

This commit is contained in:
Koosha Lahouti
2025-08-15 15:21:34 +03:30
parent 5a72b597c8
commit 0b42f4ccba
22 changed files with 845 additions and 1402 deletions

View File

@@ -8,7 +8,7 @@ import { InfoRowEdit } from './personalInformation/InfoRowEdit';
import { PageWrapper } from '../PageWrapper';
import { useManualApi } from '@/hooks/useApi';
import { Gender, type InfoRowData } from '../../types/settingsType';
import { fetchProfile, saveProfile, getToken } from '../../api/settingsApi';
import { fetchProfile, saveProfile } from '../../api/settingsApi';
export function PersonalInformation() {
const { t } = useTranslation('setting');
@@ -37,13 +37,6 @@ export function PersonalInformation() {
execute: executeSaveProfile,
} = useManualApi(saveProfile);
const {
data: tokenData,
loading: isGettingToken,
error: tokenError,
execute: executeGetToken,
} = useManualApi(getToken);
useEffect(() => {
executeFetchProfile();
}, []);
@@ -91,10 +84,6 @@ export function PersonalInformation() {
executeSaveProfile({ data, imageUrl: uploadedImageUrl });
};
const handleGetTokenClick = async () => {
executeGetToken();
};
const getErrorMessage = (error: unknown): string | null => {
if (!error) return null;
if (error instanceof Error) return error.message;
@@ -124,16 +113,6 @@ export function PersonalInformation() {
justifyContent: 'flex-end',
}}
>
<Button
variant="contained"
color="secondary"
onClick={handleGetTokenClick}
size="large"
sx={{ textTransform: 'none' }}
disabled={isLoadingProfile || isGettingToken || isSavingProfile}
>
{isGettingToken ? <CircularProgress size={24} /> : 'Get Token'}
</Button>
{isEditing ? (
<>
<Button
@@ -145,7 +124,6 @@ export function PersonalInformation() {
textTransform: 'none',
width: { xs: '100%', sm: 'auto' },
}}
disabled={isSavingProfile}
>
{t('settingForm.rejectButton')}
</Button>
@@ -186,14 +164,6 @@ export function PersonalInformation() {
{getErrorMessage(saveProfileError)}
</Typography>
)}
{tokenData?.success && (
<Typography
color="green"
sx={{ mt: 1, textAlign: 'right', width: '100%' }}
>
Token fetched and stored successfully!
</Typography>
)}
</Box>
}
>
@@ -218,11 +188,6 @@ export function PersonalInformation() {
</Box>
) : (
<>
{getErrorMessage(tokenError) && (
<Box sx={{ p: 2, mx: { xs: 2, sm: 3, md: 4 }, color: 'red' }}>
Error: {getErrorMessage(tokenError)}
</Box>
)}
<Box
sx={{
mx: { xs: 2, sm: 3, md: 4 },