diff --git a/app/api/config.ts b/app/api/config.ts index e4036f3..4457a65 100644 --- a/app/api/config.ts +++ b/app/api/config.ts @@ -23,11 +23,17 @@ export const ENDPOINTS = { history: `${API_PREFIX}/profile/login/history/all`, // // change: `${API_PREFIX}/profile/preference/login/change`, // ?login= }, - statusEdit: `${API_PREFIX}/profile/preference/status/edit`, - 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`, + status: `${API_PREFIX}/profile/preference/status/edit`, + privacy: { + stats: `${API_PREFIX}/profile/preference/privacy/stats/edit`, + counts: `${API_PREFIX}/profile/preference/privacy/counts/edit`, + socials: `${API_PREFIX}/profile/preference/privacy/social/edit`, + friendRequests: `${API_PREFIX}/profile/preference/privacy/friendRequests/edit`, + }, + socials: { + info: `${API_PREFIX}/profile/preference/social`, + edit: `${API_PREFIX}/profile/preference/social/edit`, + }, } }, filter: `${API_PREFIX}/filter`, diff --git a/app/components/Profile/Profile.EditModal.tsx b/app/components/Profile/Profile.EditModal.tsx index e889e85..ffee2c8 100644 --- a/app/components/Profile/Profile.EditModal.tsx +++ b/app/components/Profile/Profile.EditModal.tsx @@ -5,9 +5,10 @@ import { Spinner } from "../Spinner/Spinner"; import useSWR from "swr"; import { ENDPOINTS } from "#/api/config"; import { useEffect, useState } from "react"; +import { unixToDate } from "#/api/utils"; import { ProfileEditPrivacyModal } from "./Profile.EditPrivacyModal"; import { ProfileEditStatusModal } from "./Profile.EditStatusModal"; -import { unixToDate } from "#/api/utils"; +import { ProfileEditSocialModal } from "./Profile.EditSocialModal"; const fetcher = async (url: string) => { const res = await fetch(url); @@ -30,6 +31,7 @@ export const ProfileEditModal = (props: { }) => { const [privacyModalOpen, setPrivacyModalOpen] = useState(false); const [statusModalOpen, setStatusModalOpen] = useState(false); + const [socialModalOpen, setSocialModalOpen] = useState(false); const [privacyModalSetting, setPrivacyModalSetting] = useState("none"); const [privacySettings, setPrivacySettings] = useState({ privacy_stats: 9, @@ -152,7 +154,12 @@ export const ProfileEditModal = (props: { : login}
Мои социальные сети
укажите ссылки на свои страницы в соц. сетях @@ -291,6 +298,11 @@ export const ProfileEditModal = (props: { status={status} setStatus={setStatus} /> + > ); }; diff --git a/app/components/Profile/Profile.EditPrivacyModal.tsx b/app/components/Profile/Profile.EditPrivacyModal.tsx index a6e796f..5428fc9 100644 --- a/app/components/Profile/Profile.EditPrivacyModal.tsx +++ b/app/components/Profile/Profile.EditPrivacyModal.tsx @@ -26,10 +26,10 @@ export const ProfileEditPrivacyModal = (props: { }; 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}`, + privacy_stats: `${ENDPOINTS.user.settings.privacy.stats}?token=${props.token}`, + privacy_counts: `${ENDPOINTS.user.settings.privacy.counts}?token=${props.token}`, + privacy_social: `${ENDPOINTS.user.settings.privacy.socials}?token=${props.token}`, + privacy_friend_requests: `${ENDPOINTS.user.settings.privacy.friendRequests}?token=${props.token}`, }; const [loading, setLoading] = useState(false); @@ -51,6 +51,7 @@ export const ProfileEditPrivacyModal = (props: { setLoading(false); privacySettings[el.target.name] = el.target.value; props.setPrivacySettings(privacySettings); + props.setIsOpen(false) } else { new Error("failed to send data"); } diff --git a/app/components/Profile/Profile.EditSocialModal.tsx b/app/components/Profile/Profile.EditSocialModal.tsx new file mode 100644 index 0000000..0a36a66 --- /dev/null +++ b/app/components/Profile/Profile.EditSocialModal.tsx @@ -0,0 +1,206 @@ +"use client"; + +import { Button, Modal, Label, TextInput } from "flowbite-react"; +import { Spinner } from "../Spinner/Spinner"; +import { ENDPOINTS } from "#/api/config"; +import { useEffect, useState } from "react"; + +export const ProfileEditSocialModal = (props: { + isOpen: boolean; + setIsOpen: (isOpen: boolean) => void; + token: string; +}) => { + const [loading, setLoading] = useState(false); + const [updating, setUpdating] = useState(false); + const [socials, setSocials] = useState({ + vkPage: "", + tgPage: "", + discordPage: "", + instPage: "", + ttPage: "", + }); + + function _addUrl(username: string, social: string) { + if (!username) { + return ""; + } + if (username.startsWith("h")) { + return username; + } + switch (social) { + case "vk": + return `https://vk.com/${username}`; + case "tg": + return `https://t.me/${username}`; + case "inst": + return `https://instagram.com/${username}`; + case "tt": + return `https://tiktok.com/@${username}`; + } + } + + function _removeUrl(link: string) { + if (link.startsWith("https://")) { + const split = link.split("/"); + return split[split.length - 1]; + } else { + return link; + } + } + + useEffect(() => { + setLoading(true); + fetch(`${ENDPOINTS.user.settings.socials.info}?token=${props.token}`) + .then((res) => { + if (res.ok) { + return res.json(); + } + }) + .then((data) => { + setSocials({ + vkPage: data.vk_page, + tgPage: data.tg_page, + discordPage: data.discord_page, + instPage: data.inst_page, + ttPage: data.tt_page, + }); + setLoading(false); + }); + }, [props.isOpen]); + + function handleInput(e: any) { + const social = { + ...socials, + [e.target.name]: e.target.value + } + setSocials(social); + } + + function _setSocialSetting() { + const data = { + vkPage: _removeUrl(socials.vkPage), + tgPage: _removeUrl(socials.tgPage), + discordPage: _removeUrl(socials.discordPage), + instPage: _removeUrl(socials.instPage), + ttPage: _removeUrl(socials.ttPage), + }; + + setUpdating(true); + fetch(`${ENDPOINTS.user.settings.socials.edit}?token=${props.token}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }) + .then((res) => { + if (res.ok) { + setUpdating(false); + props.setIsOpen(false); + } else { + new Error("failed to send data"); + } + }) + .catch((err) => { + console.log(err); + setUpdating(false); + }); + } + + return ( + props.setIsOpen(false)} + size={"4xl"} + > + Соц. сети + + + Укажите ссылки на свои социальные сети, чтобы другие пользователи + могли с вами связаться + + {loading ? ( + + + + ) : ( + + + + + + handleInput(e)} + value={_addUrl(socials.vkPage, "vk")} + placeholder="Ссылка или никнейм" + /> + + + + + + handleInput(e)} + value={_addUrl(socials.tgPage, "tg")} + placeholder="Ссылка или никнейм" + /> + + + + + + handleInput(e)} + value={socials.discordPage} + placeholder="Никнейм" + /> + + + + + + handleInput(e)} + value={_addUrl(socials.instPage, "inst")} + placeholder="Ссылка или никнейм" + /> + + + + + + handleInput(e)} + value={_addUrl(socials.ttPage, "tt")} + placeholder="Ссылка или никнейм" + /> + + + )} + + + _setSocialSetting()} + disabled={updating} + > + Сохранить + + props.setIsOpen(false)}> + Отмена + + + + ); +}; diff --git a/app/components/Profile/Profile.EditStatusModal.tsx b/app/components/Profile/Profile.EditStatusModal.tsx index c6ee1c0..df60589 100644 --- a/app/components/Profile/Profile.EditStatusModal.tsx +++ b/app/components/Profile/Profile.EditStatusModal.tsx @@ -27,7 +27,7 @@ export const ProfileEditStatusModal = (props: { function _setStatusSetting() { setLoading(true); - fetch(`${ENDPOINTS.user.settings.statusEdit}?token=${props.token}`, { + fetch(`${ENDPOINTS.user.settings.status}?token=${props.token}`, { method: "POST", headers: { "Content-Type": "application/json",
+ Укажите ссылки на свои социальные сети, чтобы другие пользователи + могли с вами связаться +