mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 04:59:16 +00:00
adding profile detail edit modal
This commit is contained in:
parent
9d048e5e5d
commit
4b6b981d3d
@ -1,8 +1,9 @@
|
|||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { Modal, Button, Checkbox } from 'antd';
|
import { Modal, Button, Checkbox } from 'antd';
|
||||||
import { ProfileWrapper, EditImageFooter } from './Profile.styled';
|
import { ProfileWrapper, EditFooter } from './Profile.styled';
|
||||||
import { useProfile } from './useProfile.hook';
|
import { useProfile } from './useProfile.hook';
|
||||||
import { ProfileImage } from './profileImage/ProfileImage';
|
import { ProfileImage } from './profileImage/ProfileImage';
|
||||||
|
import { ProfileDetails } from './profileDetails/ProfileDetails';
|
||||||
import { Logo } from 'logo/Logo';
|
import { Logo } from 'logo/Logo';
|
||||||
import { LogoutOutlined, DatabaseOutlined, LockOutlined, RightOutlined, EditOutlined, BookOutlined, EnvironmentOutlined } from '@ant-design/icons';
|
import { LogoutOutlined, DatabaseOutlined, LockOutlined, RightOutlined, EditOutlined, BookOutlined, EnvironmentOutlined } from '@ant-design/icons';
|
||||||
|
|
||||||
@ -33,6 +34,20 @@ export function Profile({ closeProfile }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveDetails = async () => {
|
||||||
|
try {
|
||||||
|
await actions.setProfileDetails();
|
||||||
|
actions.clearEditProfileDetails();
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
Modal.error({
|
||||||
|
title: 'Failed to Save',
|
||||||
|
content: 'Please try again.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const saveSearchable = async (e) => {
|
const saveSearchable = async (e) => {
|
||||||
try {
|
try {
|
||||||
await actions.setSearchable(e.target.checked);
|
await actions.setSearchable(e.target.checked);
|
||||||
@ -59,7 +74,7 @@ export function Profile({ closeProfile }) {
|
|||||||
|
|
||||||
const Image = (
|
const Image = (
|
||||||
<div class="logo" onClick={actions.setEditProfileImage}>
|
<div class="logo" onClick={actions.setEditProfileImage}>
|
||||||
<Logo url={state.url} width={'100%'} radius={8} />
|
<Logo url={state.url} width={'100%'} radius={4} />
|
||||||
<div class="edit">
|
<div class="edit">
|
||||||
<EditOutlined />
|
<EditOutlined />
|
||||||
</div>
|
</div>
|
||||||
@ -68,16 +83,12 @@ export function Profile({ closeProfile }) {
|
|||||||
|
|
||||||
const Details = (
|
const Details = (
|
||||||
<div class="details">
|
<div class="details">
|
||||||
<div class="name">
|
<div class="name" onClick={actions.setEditProfileDetails}>
|
||||||
<div class="data">{ state.name }</div>
|
<div class="data">{ state.name }</div>
|
||||||
|
<div class="icon">
|
||||||
<EditOutlined />
|
<EditOutlined />
|
||||||
</div>
|
</div>
|
||||||
{ state.node && (
|
|
||||||
<div class="location">
|
|
||||||
<DatabaseOutlined />
|
|
||||||
<div class="data">{ state.node }</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
<div class="location">
|
<div class="location">
|
||||||
<EnvironmentOutlined />
|
<EnvironmentOutlined />
|
||||||
<div class="data">{ state.location }</div>
|
<div class="data">{ state.location }</div>
|
||||||
@ -90,14 +101,22 @@ export function Profile({ closeProfile }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const editImageFooter = (
|
const editImageFooter = (
|
||||||
<EditImageFooter>
|
<EditFooter>
|
||||||
<input type='file' id='file' accept="image/*" ref={imageFile} onChange={e => selected(e)} style={{display: 'none'}}/>
|
<input type='file' id='file' accept="image/*" ref={imageFile} onChange={e => selected(e)} style={{display: 'none'}}/>
|
||||||
<div class="select">
|
<div class="select">
|
||||||
<Button key="select" class="select" onClick={() => imageFile.current.click()}>Select Image</Button>
|
<Button key="select" class="select" onClick={() => imageFile.current.click()}>Select Image</Button>
|
||||||
</div>
|
</div>
|
||||||
<Button key="back" onClick={actions.clearEditProfileImage}>Cancel</Button>
|
<Button key="back" onClick={actions.clearEditProfileImage}>Cancel</Button>
|
||||||
<Button key="save" type="primary" onClick={saveImage}>Save</Button>
|
<Button key="save" type="primary" onClick={saveImage} loading={state.busy}>Save</Button>
|
||||||
</EditImageFooter>
|
</EditFooter>
|
||||||
|
);
|
||||||
|
|
||||||
|
const editDetailsFooter = (
|
||||||
|
<EditFooter>
|
||||||
|
<div class="select"></div>
|
||||||
|
<Button key="back" onClick={actions.clearEditProfileDetails}>Cancel</Button>
|
||||||
|
<Button key="save" type="primary" onClick={saveDetails} loading={state.busy}>Save</Button>
|
||||||
|
</EditFooter>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -145,6 +164,10 @@ export function Profile({ closeProfile }) {
|
|||||||
onCancel={actions.clearEditProfileImage}>
|
onCancel={actions.clearEditProfileImage}>
|
||||||
<ProfileImage state={state} actions={actions} />
|
<ProfileImage state={state} actions={actions} />
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<Modal title="Profile Details" centered visible={state.editProfileDetails} footer={editDetailsFooter}
|
||||||
|
onCancel={actions.clearEditProfileDetails}>
|
||||||
|
<ProfileDetails state={state} actions={actions} />
|
||||||
|
</Modal>
|
||||||
</ProfileWrapper>
|
</ProfileWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,8 @@ export const ProfileWrapper = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
border-radius: 8px;
|
border-top-left-radius: 4px;
|
||||||
|
border-bottom-right-radius: 4px;
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@ -76,9 +77,22 @@ export const ProfileWrapper = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover .icon {
|
||||||
|
border: 1px solid ${Colors.grey};
|
||||||
|
background-color: ${Colors.white};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
padding-left: 4px;
|
||||||
|
padding-right: 4px;
|
||||||
|
border: 1px solid ${Colors.profileForm};
|
||||||
|
border-raidus: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.data {
|
.data {
|
||||||
padding-right: 8px;
|
padding-right: 4px;
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
@ -136,7 +150,8 @@ export const ProfileWrapper = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
border-radius: 8px;
|
border-top-left-radius: 4px;
|
||||||
|
border-bottom-right-radius: 4px;
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@ -156,9 +171,22 @@ export const ProfileWrapper = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover .icon {
|
||||||
|
border: 1px solid ${Colors.grey};
|
||||||
|
background-color: ${Colors.white};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
padding-left: 4px;
|
||||||
|
padding-right: 4px;
|
||||||
|
border: 1px solid ${Colors.profileForm};
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.data {
|
.data {
|
||||||
padding-right: 8px;
|
padding-right: 4px;
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
@ -237,7 +265,7 @@ export const ProfileWrapper = styled.div`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
export const EditImageFooter = styled.div`
|
export const EditFooter = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
import { Input } from 'antd';
|
||||||
|
import { ProfileDetailsWrapper } from './ProfileDetails.styled';
|
||||||
|
|
||||||
|
export function ProfileDetails({ state, actions }) {
|
||||||
|
return (
|
||||||
|
<ProfileDetailsWrapper>
|
||||||
|
<div class="info">
|
||||||
|
<Input placeholder="Name" spellCheck="false" onChange={(e) => actions.setEditName(e.target.value)}
|
||||||
|
defaultValue={state.name} autocapitalizate="word" />
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<Input placeholder="Location" spellCheck="false" onChange={(e) => actions.setEditLocation(e.target.value)}
|
||||||
|
defaultValue={state.location} autocapitalizate="word" />
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<Input.TextArea placeholder="Description" onChange={(e) => actions.setEditDescription(e.target.value)}
|
||||||
|
spellCheck="false" defaultValue={state.description} autoSize={{ minRows: 2, maxRows: 6 }} />
|
||||||
|
</div>
|
||||||
|
</ProfileDetailsWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
export const ProfileDetailsWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
.info {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
@ -10,7 +10,13 @@ export function useProfile() {
|
|||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
init: false,
|
init: false,
|
||||||
editProfileImage: false,
|
editProfileImage: false,
|
||||||
|
name: null,
|
||||||
|
location: null,
|
||||||
|
description: null,
|
||||||
editImage: null,
|
editImage: null,
|
||||||
|
editName: null,
|
||||||
|
editLocation: null,
|
||||||
|
editDescription: null,
|
||||||
crop: { w: 0, h: 0, x: 0, y: 0 },
|
crop: { w: 0, h: 0, x: 0, y: 0 },
|
||||||
busy: false,
|
busy: false,
|
||||||
searchable: null,
|
searchable: null,
|
||||||
@ -56,9 +62,24 @@ export function useProfile() {
|
|||||||
clearEditProfileImage: () => {
|
clearEditProfileImage: () => {
|
||||||
updateState({ editProfileImage: false });
|
updateState({ editProfileImage: false });
|
||||||
},
|
},
|
||||||
|
setEditProfileDetails: () => {
|
||||||
|
updateState({ editProfileDetails: true });
|
||||||
|
},
|
||||||
|
clearEditProfileDetails: () => {
|
||||||
|
updateState({ editProfileDetails: false });
|
||||||
|
},
|
||||||
setEditImageCrop: (w, h, x, y) => {
|
setEditImageCrop: (w, h, x, y) => {
|
||||||
updateState({ crop: { w, h, x, y }});
|
updateState({ crop: { w, h, x, y }});
|
||||||
},
|
},
|
||||||
|
setEditName: (editName) => {
|
||||||
|
updateState({ editName });
|
||||||
|
},
|
||||||
|
setEditLocation: (editLocation) => {
|
||||||
|
updateState({ editLocation });
|
||||||
|
},
|
||||||
|
setEditDescription: (editDescription) => {
|
||||||
|
updateState({ editDescription });
|
||||||
|
},
|
||||||
setProfileImage: async () => {
|
setProfileImage: async () => {
|
||||||
if(!state.busy) {
|
if(!state.busy) {
|
||||||
updateState({ busy: true });
|
updateState({ busy: true });
|
||||||
@ -95,6 +116,23 @@ export function useProfile() {
|
|||||||
throw new Error('save in progress');
|
throw new Error('save in progress');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setProfileDetails: async () => {
|
||||||
|
if(!state.busy) {
|
||||||
|
try {
|
||||||
|
updateState({ busy: true });
|
||||||
|
await profile.actions.setProfileData(state.editName, state.editLocation, state.editDescription);
|
||||||
|
updateState({ busy: false });
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
updateState({ busy: false });
|
||||||
|
throw new Error('failed to save profile details');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('save in progress');
|
||||||
|
}
|
||||||
|
},
|
||||||
setSearchable: async (flag) => {
|
setSearchable: async (flag) => {
|
||||||
if (!state.busy) {
|
if (!state.busy) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user