-
Notifications
You must be signed in to change notification settings - Fork 0
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 #27 from Alper-Soy/develop
Prod - 08/25/2024
- Loading branch information
Showing
16 changed files
with
176 additions
and
4 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
10 changes: 10 additions & 0 deletions
10
Application/Features/Profiles/Commands/UpdateProfile/UpdateProfileCommand.cs
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,10 @@ | ||
using Application.Core; | ||
using MediatR; | ||
|
||
namespace Application.Features.Profiles.Commands.UpdateProfile; | ||
|
||
public class UpdateProfileCommand:IRequest<Result<Unit>> | ||
{ | ||
public string DisplayName { get; set; } | ||
public string Bio { get; set; } | ||
} |
25 changes: 25 additions & 0 deletions
25
Application/Features/Profiles/Commands/UpdateProfile/UpdateProfileHandler.cs
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,25 @@ | ||
using Application.Core; | ||
using Application.Interfaces; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Persistence; | ||
|
||
namespace Application.Features.Profiles.Commands.UpdateProfile; | ||
|
||
public class UpdateProfileHandler(DataContext context, IUserAccessor userAccessor) | ||
: IRequestHandler<UpdateProfileCommand, Result<Unit>> | ||
{ | ||
|
||
public async Task<Result<Unit>> Handle(UpdateProfileCommand request, CancellationToken cancellationToken) | ||
{ | ||
var user = await context.Users.FirstOrDefaultAsync(x => | ||
x.UserName == userAccessor.GetUsername()); | ||
|
||
user.Bio = request.Bio ?? user.Bio; | ||
user.DisplayName = request.DisplayName ?? user.DisplayName; | ||
|
||
var success = await context.SaveChangesAsync() > 0; | ||
|
||
return success ? Result<Unit>.Success(Unit.Value) : Result<Unit>.Failure("Problem updating profile"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Application/Features/Profiles/Commands/UpdateProfile/UpdateProfileValidator.cs
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,13 @@ | ||
using FluentValidation; | ||
|
||
namespace Application.Features.Profiles.Commands.UpdateProfile; | ||
|
||
|
||
|
||
public class UpdateProfileValidator:AbstractValidator<UpdateProfileCommand> | ||
{ | ||
public UpdateProfileValidator() | ||
{ | ||
RuleFor(x => x.DisplayName).NotEmpty(); | ||
} | ||
} |
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,40 @@ | ||
import { useState } from 'react'; | ||
import { useStore } from '../../app/stores/store'; | ||
import { Button, Grid, Header, TabPane } from 'semantic-ui-react'; | ||
import ProfileEditForm from './ProfileEditForm'; | ||
import { observer } from 'mobx-react-lite'; | ||
|
||
export default observer(function ProfileAbout() { | ||
const { profileStore } = useStore(); | ||
const { isCurrentUser, profile } = profileStore; | ||
const [editMode, setEditMode] = useState(false); | ||
|
||
return ( | ||
<TabPane> | ||
<Grid> | ||
<Grid.Column width="16"> | ||
<Header | ||
floated="left" | ||
icon="user" | ||
content={`About ${profile?.displayName}`} | ||
/> | ||
{isCurrentUser && ( | ||
<Button | ||
floated="right" | ||
basic | ||
content={editMode ? 'Cancel' : 'Edit Profile'} | ||
onClick={() => setEditMode(!editMode)} | ||
/> | ||
)} | ||
</Grid.Column> | ||
<Grid.Column width="16"> | ||
{editMode ? ( | ||
<ProfileEditForm setEditMode={setEditMode} /> | ||
) : ( | ||
<span style={{ whiteSpace: 'pre-wrap' }}>{profile?.bio}</span> | ||
)} | ||
</Grid.Column> | ||
</Grid> | ||
</TabPane> | ||
); | ||
}); |
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,43 @@ | ||
import { Form, Formik } from 'formik'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Button } from 'semantic-ui-react'; | ||
import { useStore } from '../../app/stores/store'; | ||
import * as Yup from 'yup'; | ||
import TextInput from '../../app/common/form/TextInput'; | ||
import TextAreaInput from '../../app/common/form/TextArea'; | ||
|
||
interface Props { | ||
setEditMode: (editMode: boolean) => void; | ||
} | ||
export default observer(function ProfileEditForm({ setEditMode }: Props) { | ||
const { | ||
profileStore: { profile, updateProfile }, | ||
} = useStore(); | ||
return ( | ||
<Formik | ||
initialValues={{ displayName: profile?.displayName, bio: profile?.bio }} | ||
onSubmit={(values) => { | ||
updateProfile(values).then(() => { | ||
setEditMode(false); | ||
}); | ||
}} | ||
validationSchema={Yup.object({ | ||
displayName: Yup.string().required(), | ||
})} | ||
> | ||
{({ isSubmitting, isValid, dirty }) => ( | ||
<Form className="ui form"> | ||
<TextInput placeholder="Display Name" name="displayName" /> | ||
<TextAreaInput rows={3} placeholder="Add your bio" name="bio" /> | ||
<Button | ||
positivetype="submit" | ||
loading={isSubmitting} | ||
content="Update profile" | ||
floated="right" | ||
disabled={!isValid || !dirty} | ||
/> | ||
</Form> | ||
)} | ||
</Formik> | ||
); | ||
}); |