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.
refactor(ui): update BrandUpload component
robinf86386940610
diff --git a/ui/src/components/BrandUpload/index.tsx b/ui/src/components/BrandUpload/index.tsxindex 477efea0..c830ac2a 100644--- a/ui/src/components/BrandUpload/index.tsx+++ b/ui/src/components/BrandUpload/index.tsx@@ -2,33 +2,38 @@ import { FC } from 'react';import { ButtonGroup, Button } from 'react-bootstrap';import { Icon, UploadImg } from '@/components';+import { uploadAvatar } from '@/services';interface Props {- type: string;- imgPath: string;- uploadCallback: (data: FormData) => Promise<any>;- deleteCallback: (type: string) => void;+ type: 'logo' | 'avatar';+ value: string;+ onChange: (value: string) => void;}-const Index: FC<Props> = ({- type,- imgPath,- uploadCallback,- deleteCallback,-}) => {+const Index: FC<Props> = ({ type = 'logo', value, onChange }) => {+ const onUpload = (file: any) => {+ return new Promise((resolve) => {+ uploadAvatar(file).then((res) => {+ onChange(res);+ resolve(true);+ });+ });+ };++ const onRemove = () => {+ onChange('');+ };return (<div className="d-flex"><div className="bg-gray-300 upload-img-wrap me-2 d-flex align-items-center justify-content-center">- <img src={imgPath} alt="" height={100} />+ <img src={value} alt="" height={100} /></div><ButtonGroup vertical className="fit-content">- <UploadImg type={type} upload={uploadCallback} className="mb-0">+ <UploadImg type={type} upload={onUpload} className="mb-0"><Icon name="cloud-upload" /></UploadImg>- <Button- variant="outline-secondary"- onClick={() => deleteCallback(type)}>+ <Button variant="outline-secondary" onClick={onRemove}><Icon name="trash" /></Button></ButtonGroup>