Skip to content

Commit

Permalink
Поправил форму смены пароля
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikMix committed Mar 21, 2024
1 parent 6d8580f commit 33cdbd8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 50 deletions.
7 changes: 2 additions & 5 deletions public/src/components/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {ScReact} from "@veglem/screact";
import {Img} from "../Image/Image";
import "./Profile.sass"
import {Button} from "../Button/Button";
import {AppUserStore, UserActions} from "../../modules/stores/UserStore";
import {AppUserStore, UserActions, UserStoreState} from "../../modules/stores/UserStore";
import {AppDispatcher} from "../../modules/dispatcher";
import {UpdatePasswordForm} from "../UpdatePassword/UpdatePassword";
import {AppToasts} from "../Toasts/Toasts";
import {imagesUlr} from "../../modules/api";

const MEGABYTE_SIZE = 1024 * 1024
const MAX_AVATAR_SIZE = MEGABYTE_SIZE
const MAX_AVATAR_SIZE = 2 * MEGABYTE_SIZE

export class Profile extends ScReact.Component<any, any> {
state = {
Expand Down Expand Up @@ -122,11 +122,8 @@ export class Profile extends ScReact.Component<any, any> {
</div>
</div>

{/*{this.state.updatePasswordFormOpen ? <UpdatePasswordForm open={this.state.updatePasswordFormOpen} closeModal={this.closeModal}/> : "" }*/}

<UpdatePasswordForm />


</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion public/src/components/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Toast extends ScReact.Component<ToastProps, ToastState> {
}

componentWillUnmount() {
this.state.timer && clearTimeout(this.state.timer)
clearTimeout(this.state.timer)
}

closeToast = () => {
Expand Down
3 changes: 2 additions & 1 deletion public/src/components/Toasts/Toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export class Toasts extends ScReact.Component<any, ToastState> {
toasts: state.toasts.concat(toast)
}))

// this.state.toasts.splice(1).forEach(toast => {
// TODO: Ограничить количество тостов
// this.state.toasts.splice(4).forEach(toast => {
// this.removeToast(toast.id)
// })
}
Expand Down
41 changes: 12 additions & 29 deletions public/src/components/UpdatePassword/UpdatePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "./UpdatePassword.sass"
import {ValidatePassword} from "../../modules/validation";
import {AppDispatcher} from "../../modules/dispatcher";
import {AppUserStore, UserActions, UserStoreState} from "../../modules/stores/UserStore";
import {AppToasts} from "../Toasts/Toasts";

export class UpdatePasswordForm extends ScReact.Component<any, any> {
state = {
Expand Down Expand Up @@ -43,39 +42,23 @@ export class UpdatePasswordForm extends ScReact.Component<any, any> {
open: store.updatePasswordFormOpen
}))

if (store.errorUpdatePasswordForm == "Неправильный пароль") {
this.setPasswordError("Неправильный пароль")
this.setPasswordValidated(false)
} else {
// TODO
// При логауте все крашится
// Рекурсия блин получается

if (this.state.open) {
this.closeModal()
AppDispatcher.dispatch(UserActions.CLOSE_CHANGE_PASSWORD_FORM)
AppToasts.success("Пароль успешно изменен")
}
if (!this.state.open) {
setTimeout(() => {
this.setState(() => ({
password: "",
errorPassword: "",
passwordValidationResult: false,

repeatPassword: "",
errorRepeatPassword: "",
repeatPasswordValidationResult: false
}))
}, 500)
}
}

closeModal = () => {
// TODO
// this.state.timer = setTimeout(() => {
// this.setState(() => ({
// password: "",
// errorPassword: "",
// passwordValidationResult: false,
//
// repeatPassword: "",
// errorRepeatPassword: "",
// repeatPasswordValidationResult: false
// }))
// }, 500)

console.log("closeModal")
AppDispatcher.dispatch(UserActions.CLOSE_CHANGE_PASSWORD_FORM)

}

setPassword = (value:string) => {
Expand Down
5 changes: 0 additions & 5 deletions public/src/modules/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ class AuthRequests {

public Login = async (username: string, password: string) => {

console.log(username)
console.log(password)

const response = await Ajax.Post(this.baseUrl + "/login", {
body: {
username,
Expand Down Expand Up @@ -133,8 +130,6 @@ class AuthRequests {
};
}

console.log(response.status)

throw Error(response.body.message);
};

Expand Down
16 changes: 7 additions & 9 deletions public/src/modules/stores/UserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {AppDispatcher} from "../dispatcher";
import {AppAuthRequests, AppProfileRequests} from "../api";
import {AppRouter} from "../router";
import {BaseStore} from "./BaseStore";
import {AppToasts} from "../../components/Toasts/Toasts";

export type UserStoreState = {
JWT: string | null | undefined,
Expand Down Expand Up @@ -176,20 +177,16 @@ class UserStore extends BaseStore<UserStoreState>{

private async updatePassword({oldPassword, newPassword}) {
try {
console.log("updatePassword")
await AppProfileRequests.UpdatePassword(oldPassword, newPassword, this.state.JWT)

// TODO
// new Toast
AppToasts.success("Пароль успешно изменен")

this.SetState(state => ({
...state,
errorUpdatePasswordForm: undefined
}))
this.closeChangePasswordForm()
}
catch (err) {
if (err.message == "Неверный пароль") {
console.log("fsdadfasdfasdf")
AppToasts.error("Неверный пароль")

this.SetState(state => ({
...state,
errorUpdatePasswordForm: "Неправильный пароль"
Expand All @@ -208,7 +205,8 @@ class UserStore extends BaseStore<UserStoreState>{
private closeChangePasswordForm() {
this.SetState(state => ({
...state,
updatePasswordFormOpen: false
updatePasswordFormOpen: false,
errorUpdatePasswordForm: undefined
}))
}
}
Expand Down

0 comments on commit 33cdbd8

Please sign in to comment.