mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-06 00:04:39 +00:00
feat: send privacy setting edit request
This commit is contained in:
parent
d7508a5e13
commit
5f92074558
2 changed files with 42 additions and 3 deletions
|
@ -18,6 +18,10 @@ export const ENDPOINTS = {
|
||||||
favorite: `${API_PREFIX}/favorite`,
|
favorite: `${API_PREFIX}/favorite`,
|
||||||
settings: {
|
settings: {
|
||||||
my: `${API_PREFIX}/profile/preference/my`,
|
my: `${API_PREFIX}/profile/preference/my`,
|
||||||
|
statsEdit: `${API_PREFIX}/profile/preference/privacy/stats/edit`,
|
||||||
|
countsEdit: `${API_PREFIX}/profile/preference/privacy/counts/edit`,
|
||||||
|
socialEdit: `${API_PREFIX}/profile/preference/privacy/social/edit`,
|
||||||
|
friendRequestsEdit: `${API_PREFIX}/profile/preference/privacy/friendRequests/edit`,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filter: `${API_PREFIX}/filter`,
|
filter: `${API_PREFIX}/filter`,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import { Modal } from "flowbite-react";
|
import { Modal } from "flowbite-react";
|
||||||
import { ENDPOINTS } from "#/api/config";
|
import { ENDPOINTS } from "#/api/config";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export const ProfileEditPrivacyModal = (props: {
|
export const ProfileEditPrivacyModal = (props: {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
@ -16,7 +17,6 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
};
|
};
|
||||||
setPrivacySettings: (privacySettings: any) => void;
|
setPrivacySettings: (privacySettings: any) => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const setting_text = {
|
const setting_text = {
|
||||||
privacy_stats: "Кто видит мою статистику, оценки и историю просмотра",
|
privacy_stats: "Кто видит мою статистику, оценки и историю просмотра",
|
||||||
privacy_counts:
|
privacy_counts:
|
||||||
|
@ -25,10 +25,40 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
privacy_friend_requests: "Кто может отправлять мне заявки в друзья",
|
privacy_friend_requests: "Кто может отправлять мне заявки в друзья",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _endpoints = {
|
||||||
|
privacy_stats: `${ENDPOINTS.user.settings.statsEdit}?token=${props.token}`,
|
||||||
|
privacy_counts: `${ENDPOINTS.user.settings.countsEdit}?token=${props.token}`,
|
||||||
|
privacy_social: `${ENDPOINTS.user.settings.socialEdit}?token=${props.token}`,
|
||||||
|
privacy_friend_requests: `${ENDPOINTS.user.settings.friendRequestsEdit}?token=${props.token}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
function _setPrivacySetting(el: any) {
|
function _setPrivacySetting(el: any) {
|
||||||
let privacySettings = structuredClone(props.privacySettings);
|
let privacySettings = structuredClone(props.privacySettings);
|
||||||
privacySettings[el.target.name] = el.target.value;
|
setLoading(true);
|
||||||
props.setPrivacySettings(privacySettings);
|
fetch(_endpoints[props.setting], {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
permission: el.target.value,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (res.ok) {
|
||||||
|
setLoading(false);
|
||||||
|
privacySettings[el.target.name] = el.target.value;
|
||||||
|
props.setPrivacySettings(privacySettings);
|
||||||
|
} else {
|
||||||
|
new Error("failed to send data");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -47,6 +77,7 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<input
|
<input
|
||||||
|
disabled={loading}
|
||||||
onClick={(e) => _setPrivacySetting(e)}
|
onClick={(e) => _setPrivacySetting(e)}
|
||||||
checked={props.privacySettings[props.setting] == 0}
|
checked={props.privacySettings[props.setting] == 0}
|
||||||
id="default-radio-1"
|
id="default-radio-1"
|
||||||
|
@ -64,6 +95,7 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<input
|
<input
|
||||||
|
disabled={loading}
|
||||||
onClick={(e) => _setPrivacySetting(e)}
|
onClick={(e) => _setPrivacySetting(e)}
|
||||||
checked={props.privacySettings[props.setting] == 1}
|
checked={props.privacySettings[props.setting] == 1}
|
||||||
id="default-radio-2"
|
id="default-radio-2"
|
||||||
|
@ -84,6 +116,7 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<input
|
<input
|
||||||
|
disabled={loading}
|
||||||
onClick={(e) => _setPrivacySetting(e)}
|
onClick={(e) => _setPrivacySetting(e)}
|
||||||
checked={props.privacySettings[props.setting] == 0}
|
checked={props.privacySettings[props.setting] == 0}
|
||||||
id="default-radio-1"
|
id="default-radio-1"
|
||||||
|
@ -101,6 +134,7 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<input
|
<input
|
||||||
|
disabled={loading}
|
||||||
onClick={(e) => _setPrivacySetting(e)}
|
onClick={(e) => _setPrivacySetting(e)}
|
||||||
checked={props.privacySettings[props.setting] == 1}
|
checked={props.privacySettings[props.setting] == 1}
|
||||||
id="default-radio-2"
|
id="default-radio-2"
|
||||||
|
@ -118,6 +152,7 @@ export const ProfileEditPrivacyModal = (props: {
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<input
|
<input
|
||||||
|
disabled={loading}
|
||||||
onClick={(e) => _setPrivacySetting(e)}
|
onClick={(e) => _setPrivacySetting(e)}
|
||||||
checked={props.privacySettings[props.setting] == 2}
|
checked={props.privacySettings[props.setting] == 2}
|
||||||
id="default-radio-3"
|
id="default-radio-3"
|
||||||
|
|
Loading…
Add table
Reference in a new issue