Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: custom avatar need upload

shuaia4d55e629cb2
diff --git a/ui/src/components/Avatar/index.tsx b/ui/src/components/Avatar/index.tsx
index 9a8c3d6d..f9d5bd6f 100644
--- a/ui/src/components/Avatar/index.tsx
+++ b/ui/src/components/Avatar/index.tsx
@@ -21,9 +21,9 @@ const Index: FC<IProps> = ({ avatar, size, className, searchStr = '' }) => {
avatar?.includes('gravatar') ? '&d=identicon' : ''
}`;
}
- } else if (avatar?.type === 'gravatar') {
+ } else if (avatar?.type === 'gravatar' && avatar.gravatar) {
url = `${avatar.gravatar}?${searchStr}&d=identicon`;
- } else if (avatar?.type === 'custom') {
+ } else if (avatar?.type === 'custom' && avatar.custom) {
url = `${avatar.custom}?${searchStr}`;
}
diff --git a/ui/src/i18n/locales/en.json b/ui/src/i18n/locales/en.json
index 94277ee9..127e24f2 100644
--- a/ui/src/i18n/locales/en.json
+++ b/ui/src/i18n/locales/en.json
@@ -523,7 +523,8 @@
"custom": "Custom",
"btn_refresh": "Refresh",
"custom_text": "You can upload your image.",
- "default": "Default"
+ "default": "Default",
+ "msg": "Please upload an avatar"
},
"bio": {
"label": "About Me (optional)"
diff --git a/ui/src/pages/Users/Settings/Profile/index.tsx b/ui/src/pages/Users/Settings/Profile/index.tsx
index e5cd9295..84478fd1 100644
--- a/ui/src/pages/Users/Settings/Profile/index.tsx
+++ b/ui/src/pages/Users/Settings/Profile/index.tsx
@@ -120,6 +120,17 @@ const Index: React.FC = () => {
};
}
+ if (formData.avatar.type === 'custom' && !formData.avatar.custom) {
+ bol = false;
+ formData.avatar = {
+ ...formData.avatar,
+ custom: '',
+ value: '',
+ isInvalid: true,
+ errorMsg: t('avatar.msg'),
+ };
+ }
+
const reg = /^(http|https):\/\//g;
if (website.value && !website.value.match(reg)) {
bol = false;
@@ -368,6 +379,13 @@ const Index: React.FC = () => {
<Avatar size="128px" avatar="" className="me-3 rounded" />
)}
</div>
+ <Form.Control
+ isInvalid={formData.avatar.isInvalid}
+ className="d-none"
+ />
+ <Form.Control.Feedback type="invalid">
+ {formData.avatar.errorMsg}
+ </Form.Control.Feedback>
</Form.Group>
<Form.Group controlId="bio" className="mb-3">