获取昵称修改状态、优化昵称修改逻辑
This commit is contained in:
@@ -33,7 +33,6 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
const [isValid, setIsValid] = useState(true);
|
||||
const [isIllegal, setIsIllegal] = useState(false);
|
||||
const [hasIllegal, setHasIllegal] = useState(false);
|
||||
const [canEdit, setCanEdit] = useState(true);
|
||||
// 使用全局键盘状态
|
||||
const {
|
||||
keyboardHeight,
|
||||
@@ -89,15 +88,11 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
value.length >= 2 &&
|
||||
value.length <= maxLength &&
|
||||
!hasIllegal &&
|
||||
!isIllegal &&
|
||||
canEdit;
|
||||
!isIllegal;
|
||||
setIsValid(valid);
|
||||
}, [
|
||||
value, hasIllegal, isIllegal, canEdit
|
||||
])
|
||||
}, [value, hasIllegal, isIllegal]);
|
||||
|
||||
const handle_save = () => {
|
||||
console.log("savexxxxxxx", isIllegal, hasIllegal, !isValid)
|
||||
if (isIllegal) {
|
||||
Taro.showToast({
|
||||
title: "输入的字符非法",
|
||||
@@ -106,7 +101,6 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
});
|
||||
return;
|
||||
} else if (hasIllegal) {
|
||||
console.log("hasIllegal")
|
||||
Taro.showToast({
|
||||
title: "内容不能包含@<>/等无效字符",
|
||||
icon: "none",
|
||||
@@ -128,7 +122,6 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
setValue(initialValue);
|
||||
setHasIllegal(false);
|
||||
setIsIllegal(false);
|
||||
setCanEdit(true);
|
||||
onCancel();
|
||||
};
|
||||
|
||||
@@ -176,12 +169,15 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
confirmType="done"
|
||||
// autoFocus={true}
|
||||
onConfirm={handle_save}
|
||||
onBlur={(e) => { e.preventDefault() }}
|
||||
onBlur={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
/>
|
||||
<View className="char_count">
|
||||
<Text
|
||||
className={`count_text ${value.length > maxLength && "un-valid"
|
||||
}`}
|
||||
className={`count_text ${
|
||||
value.length > maxLength && "un-valid"
|
||||
}`}
|
||||
>
|
||||
{value.length}/{maxLength}
|
||||
</Text>
|
||||
@@ -208,8 +204,9 @@ const EditModal: React.FC<EditModalProps> = ({
|
||||
/>
|
||||
<View className="char_count">
|
||||
<Text
|
||||
className={`count_text ${value.length > maxLength && "un-valid"
|
||||
}`}
|
||||
className={`count_text ${
|
||||
value.length > maxLength && "un-valid"
|
||||
}`}
|
||||
>
|
||||
{value.length}/{maxLength}
|
||||
</Text>
|
||||
|
||||
@@ -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