mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
some cleanup
This commit is contained in:
1 parent
a097c9f1c0
commit
e0b272d548
4 files changed
+34
-45
No files matched your search
@@ -35,9 +35,6 @@ const Modal: React.FC<ModalProps> = ({
|
||||
const fadeIn = useSpring({
|
||||
opacity: show ? 1 : 0,
|
||||
config: { duration: 80, easing: t => t },
|
||||
// onRest: () => {
|
||||
// if (!show) handleClose();
|
||||
// },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function LoginView({ animating, errorType = "", handleClose, logi
|
||||
</div>
|
||||
</header>
|
||||
{ errorType ? <p {...{ className: "error-message" }}>{ errorStrings[Object.keys(ErrorTypes).indexOf(errorType)] }</p> : null }
|
||||
<TempInput {...{ icon: faUser, label: "Username or email", placeholder: "Username", ...loginProps("username") }}/>
|
||||
<TempInput {...{ icon: faUser, label: "Username or email", placeholder: "Username", ...loginProps("usernameOrEmail") }}/>
|
||||
<TempInput {...{ icon: faKey, label: "Password", placeholder: "Enter your password", type: "password", ...loginProps("password") }}/>
|
||||
<button {...{ className: "btn btn-primary w-100 mt-4", disabled: animating, onClick: login }}>Login</button>
|
||||
</div>;
|
||||
|
||||
@@ -18,7 +18,6 @@ export default function useLogin({ onSuccess, status, statusSet }: Props) {
|
||||
});
|
||||
|
||||
const login = () => {
|
||||
console.log("🐊",);
|
||||
errorTypeSet("");
|
||||
statusSet(FetchStatus.in_progress);
|
||||
// if (allAreValid()) {
|
||||
@@ -26,7 +25,6 @@ export default function useLogin({ onSuccess, status, statusSet }: Props) {
|
||||
username_or_email: state.usernameOrEmail.value,
|
||||
password: state.password.value,
|
||||
}).then((res: CreateSessionResponse) => {
|
||||
console.log("🦋",res);
|
||||
if (!res.success && res.error_type) {
|
||||
statusSet(FetchStatus.error);
|
||||
errorTypeSet(res.error_type);
|
||||
|
||||
@@ -171,47 +171,41 @@ export default function useSignup({ onSuccess, status, statusSet }: Props) {
|
||||
});
|
||||
|
||||
const signup = () => {
|
||||
console.log("🐊",);
|
||||
statusSet(FetchStatus.in_progress);
|
||||
// if (allAreValid()) {
|
||||
CreateAccount("",{
|
||||
username: state.username.value,
|
||||
email_address: state.email.value,
|
||||
password: state.password.value,
|
||||
password_confirmation: state.passwordConfirm.value,
|
||||
}).then((res: CreateAccountResponse) => {
|
||||
console.log("🦋",res);
|
||||
// let updates = {}
|
||||
if (res && res.error_fields && res.error_type) {
|
||||
statusSet(FetchStatus.error);
|
||||
if (res.error_fields.email_address) {
|
||||
console.log("🍟",res.error_type);
|
||||
switch (res.error_type) {
|
||||
case "BadInput": return update({ name: "email", reason: EmailReasons.BadInput, validation: InputValidation.Invalid });
|
||||
case "EmailTaken": return update({ name: "email", reason: EmailReasons.EmailTaken, validation: InputValidation.Invalid });
|
||||
}
|
||||
return;
|
||||
} else if (res.error_fields.password) {
|
||||
switch (res.error_type) {
|
||||
case "TooShort": update({ name: "password", reason: PasswordReasons.TooShort, validation: InputValidation.Invalid });
|
||||
}
|
||||
} else if (res.error_fields?.username) {
|
||||
let updateUsername = (reason: UsernameReasons) => update({ reason, name: "username", validation: InputValidation.Invalid });
|
||||
switch (res.error_fields.username) {
|
||||
case "invalid username characters": return updateUsername(UsernameReasons.InvalidCharacters);
|
||||
case "username is too long": return updateUsername(UsernameReasons.TooLong);
|
||||
case "username is taken": return updateUsername(UsernameReasons.IsTaken);
|
||||
case "username is reserved": return updateUsername(UsernameReasons.IsReserved);
|
||||
case "username contains slurs": return updateUsername(UsernameReasons.ContainsSlurs);
|
||||
}
|
||||
CreateAccount("",{
|
||||
username: state.username.value,
|
||||
email_address: state.email.value,
|
||||
password: state.password.value,
|
||||
password_confirmation: state.passwordConfirm.value,
|
||||
}).then((res: CreateAccountResponse) => {
|
||||
if (res && res.error_fields && res.error_type) {
|
||||
statusSet(FetchStatus.error);
|
||||
if (res.error_fields.email_address) {
|
||||
switch (res.error_type) {
|
||||
case "BadInput": return update({ name: "email", reason: EmailReasons.BadInput, validation: InputValidation.Invalid });
|
||||
case "EmailTaken": return update({ name: "email", reason: EmailReasons.EmailTaken, validation: InputValidation.Invalid });
|
||||
}
|
||||
} else if (res.success) {
|
||||
statusSet(FetchStatus.success);
|
||||
querySession();
|
||||
if (onSuccess) onSuccess(res);
|
||||
}
|
||||
});
|
||||
// }
|
||||
return;
|
||||
} else if (res.error_fields.password) {
|
||||
switch (res.error_type) {
|
||||
case "TooShort": update({ name: "password", reason: PasswordReasons.TooShort, validation: InputValidation.Invalid });
|
||||
}
|
||||
} else if (res.error_fields?.username) {
|
||||
let updateUsername = (reason: UsernameReasons) => update({ reason, name: "username", validation: InputValidation.Invalid });
|
||||
switch (res.error_fields.username) {
|
||||
case "invalid username characters": return updateUsername(UsernameReasons.InvalidCharacters);
|
||||
case "username is too long": return updateUsername(UsernameReasons.TooLong);
|
||||
case "username is taken": return updateUsername(UsernameReasons.IsTaken);
|
||||
case "username is reserved": return updateUsername(UsernameReasons.IsReserved);
|
||||
case "username contains slurs": return updateUsername(UsernameReasons.ContainsSlurs);
|
||||
}
|
||||
}
|
||||
} else if (res.success) {
|
||||
statusSet(FetchStatus.success);
|
||||
querySession();
|
||||
if (onSuccess) onSuccess(res);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return { allAreValid, setProps, signup, state, update };
|
||||
|
||||
Reference in new issue
Block a user