-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #870 from bounswe/main
Deploying latest changes - 26.11.2023 22:09
- Loading branch information
Showing
27 changed files
with
845 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { EditFilled } from "@ant-design/icons"; | ||
import { Button, Form, Input, Modal, Radio } from "antd"; | ||
import { useEffect, useState } from "react"; | ||
import { editProfile } from "../../Services/profile"; | ||
import UploadArea from "../UploadArea/UploadArea"; | ||
import { useForm } from "antd/es/form/Form"; | ||
import { useMutation, useQueryClient } from "react-query"; | ||
import { message } from "antd"; | ||
|
||
function EditProfile({ profile }: { profile: any }) { | ||
const profileId = profile.id; | ||
const [open, setOpen] = useState(false); | ||
const [confirmLoading, setConfirmLoading] = useState(false); | ||
const [imageUrl, setImageUrl] = useState<string | undefined>(); | ||
const queryClient = useQueryClient(); | ||
const [form] = useForm(); | ||
|
||
useEffect(() => { | ||
form.setFieldsValue(profile); | ||
form.setFieldValue("username", profile?.user?.username); | ||
setImageUrl(profile?.profilePhoto); | ||
}, [profile]); | ||
|
||
const showModal = () => { | ||
setOpen(true); | ||
}; | ||
|
||
const { mutate: edit } = useMutation( | ||
(data: any) => editProfile(data, profileId), | ||
{ | ||
onSuccess() { | ||
queryClient.invalidateQueries(["profile", profile.user.id]); | ||
setConfirmLoading(false); | ||
setOpen(false); | ||
}, | ||
onError(error: any) { | ||
message.error(error.message); | ||
setConfirmLoading(false); | ||
}, | ||
} | ||
); | ||
|
||
const handleConfirm = async (data: any) => { | ||
setConfirmLoading(true); | ||
const newdata = { ...data, ...{ profilePhoto: imageUrl } }; | ||
console.log(newdata); | ||
edit(newdata); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setOpen(false); | ||
}; | ||
|
||
const onFinish = async (data: any) => { | ||
await handleConfirm(data); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button icon={<EditFilled />} type="primary" onClick={showModal}> | ||
Edit Profile | ||
</Button> | ||
<Modal | ||
title="Edit Profile" | ||
open={open} | ||
onCancel={handleCancel} | ||
style={{ | ||
maxWidth: "70%", | ||
minWidth: "700px", | ||
display: "flex", | ||
flexDirection: "column", | ||
}} | ||
footer={[ | ||
<Button | ||
key="submit" | ||
type="primary" | ||
loading={confirmLoading} | ||
onClick={handleConfirm} | ||
htmlType="submit" | ||
form="editProfileForm" | ||
> | ||
Confirm Changes | ||
</Button>, | ||
]} | ||
forceRender | ||
> | ||
<Form | ||
onFinish={onFinish} | ||
labelCol={{ span: 6 }} | ||
wrapperCol={{ span: 14 }} | ||
layout="horizontal" | ||
id="editProfileForm" | ||
form={form} | ||
> | ||
<Form.Item label="Profile Photo"> | ||
<UploadArea | ||
style={{ height: "200px", width: "200px" }} | ||
onUpload={setImageUrl} | ||
/> | ||
</Form.Item> | ||
<Form.Item label="Username" name="username"> | ||
<Input /> | ||
</Form.Item> | ||
<Form.Item label="Privacy" name="isPrivate"> | ||
<Radio.Group> | ||
<Radio value={true}> private </Radio> | ||
<Radio value={false}> public </Radio> | ||
</Radio.Group> | ||
</Form.Item> | ||
<Form.Item label="Steam Profile" name="steamProfile"> | ||
<Input /> | ||
</Form.Item> | ||
<Form.Item label="Epic Games Profile" name="epicGamesProfile"> | ||
<Input /> | ||
</Form.Item> | ||
<Form.Item label="XBOX Profile" name="xboxProfile"> | ||
<Input /> | ||
</Form.Item> | ||
</Form> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
|
||
export default EditProfile; |
17 changes: 17 additions & 0 deletions
17
app/frontend/src/Components/UploadArea/UploadArea.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.uploadContainer { | ||
border: 2px dashed #d9d9d9; | ||
border-radius: 4px; | ||
padding: 16px; | ||
text-align: center; | ||
|
||
&:hover { | ||
border-color: #40a9ff; | ||
} | ||
} | ||
|
||
.dragger { | ||
height: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useState } from "react"; | ||
import { Upload } from "antd"; | ||
import { useMutation } from "react-query"; | ||
import axios from "axios"; | ||
import styles from "./UploadArea.module.scss"; | ||
import { uploadImage } from "../../Services/image"; | ||
|
||
interface UploadAreaProps { | ||
style?: React.CSSProperties; | ||
onUpload?: (url: string) => void; | ||
} | ||
|
||
const UploadArea: React.FC<UploadAreaProps> = ({ style, onUpload }) => { | ||
const [imageUrl, setImageUrl] = useState<string | null>(null); | ||
const uploadMutation = useMutation( | ||
({ image }: { image: File }) => uploadImage(image, "post-imgs"), | ||
{ | ||
onSuccess: (data) => { | ||
setImageUrl(data); // Assuming 'data.url' is the URL of the uploaded image | ||
onUpload?.(data); | ||
}, | ||
} | ||
); | ||
|
||
const handleUpload = async (file: any) => { | ||
uploadMutation.mutate({ image: file }); | ||
}; | ||
|
||
return ( | ||
<div className={styles.uploadContainer} style={style}> | ||
{!imageUrl ? ( | ||
<Upload.Dragger | ||
name="file" | ||
customRequest={({ file }) => handleUpload(file)} | ||
className={styles.dragger} | ||
showUploadList={false} | ||
accept="image/*" | ||
> | ||
<p className="ant-upload-text"> | ||
Click or drag file to this area to upload | ||
</p> | ||
</Upload.Dragger> | ||
) : ( | ||
<div className={styles.imagePreview}> | ||
<img | ||
src={`${import.meta.env.VITE_APP_IMG_URL}${imageUrl}`} | ||
alt="Uploaded" | ||
style={{ maxWidth: "100%", maxHeight: "100%" }} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default UploadArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.