获取昵称修改状态、优化昵称修改逻辑
This commit is contained in:
@@ -6,7 +6,7 @@ import "./index.scss";
|
||||
import { EditModal } from "@/components";
|
||||
import { UserService, PickerOption } from "@/services/userService";
|
||||
import { PopupPicker } from "@/components/Picker/index";
|
||||
import { useUserActions } from "@/store/userStore";
|
||||
import { useUserActions, useNicknameChangeStatus } from "@/store/userStore";
|
||||
import { UserInfoType } from "@/services/userService";
|
||||
import { useCities, useProfessions } from "@/store/pickerOptionsStore";
|
||||
import { formatNtrpDisplay } from "@/utils/helper";
|
||||
@@ -77,8 +77,9 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
||||
set_user_info,
|
||||
onTab,
|
||||
}) => {
|
||||
const nickname_change_status = useNicknameChangeStatus();
|
||||
const { setShowGuideBar } = useGlobalState();
|
||||
const { updateUserInfo } = useUserActions();
|
||||
const { updateUserInfo, updateNickname } = useUserActions();
|
||||
const [ntrpTested, setNtrpTested] = useState(false);
|
||||
|
||||
// 使用 useRef 记录上一次的 user_info,只在真正变化时打印
|
||||
@@ -185,6 +186,13 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
||||
}
|
||||
if (field === "nickname") {
|
||||
if (!is_current_user) return;
|
||||
if (!nickname_change_status.can_change) {
|
||||
return Taro.showToast({
|
||||
title: `30天内仅可修改4次昵称,${nickname_change_status.next_period_start_time}后可修改`,
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
// 手动输入
|
||||
setShowGuideBar(false);
|
||||
setEditingField(field);
|
||||
@@ -200,10 +208,10 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
||||
try {
|
||||
// 调用更新用户信息接口,只传递修改的字段
|
||||
const update_data = { [editing_field]: value };
|
||||
await UserService.update_user_info(update_data);
|
||||
|
||||
await updateUserInfo({ [editing_field]: value });
|
||||
|
||||
// await UserService.update_user_info(update_data);
|
||||
editing_field === "nickname"
|
||||
? await updateNickname(value)
|
||||
: await updateUserInfo(update_data);
|
||||
set_form_data((prev) => {
|
||||
return { ...prev, ...update_data };
|
||||
});
|
||||
@@ -607,7 +615,7 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
|
||||
onCancel={handle_edit_modal_cancel}
|
||||
validationMessage={
|
||||
editing_field === "nickname"
|
||||
? "请填写 2-24 个字符,不包括 @<>/等无效字符。30 天内可修改 4 次昵称,12.5 前还可修改 4 次。"
|
||||
? `请填写 2-24 个字符,不包括 @<>/等无效字符。30 天内可修改 4 次昵称,${nickname_change_status.next_period_start_time} 前还可修改 ${nickname_change_status.remaining_count} 次。`
|
||||
: "请填写 2-100 个字符"
|
||||
}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user