Skip to content

Commit

Permalink
feat: UX Improvement
Browse files Browse the repository at this point in the history
401error -> login page direction, error alert message change
Signup/Login Button textclass, language variance
  • Loading branch information
jun-brro committed Mar 10, 2024
1 parent 7f4a428 commit 7756f76
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 34 deletions.
16 changes: 14 additions & 2 deletions my-app/src/components/AuthButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ const AuthButtons: React.FC = () => {
) : (
<>
<Link to="/login">
<button>{language === "ko" ? "로그인하기" : "Login"}</button>
<button
className={`${textClassName} ${
isHighContrast ? "text-yellow-300" : "text-neutral-800"
}`}
>
{language === "ko" ? "로그인하기" : "Login"}
</button>
</Link>
<Link to="/signup">
<button>{language === "ko" ? "회원가입" : "Sign Up"}</button>
<button
className={`${textClassName} ${
isHighContrast ? "text-yellow-300" : "text-neutral-800"
}`}
>
{language === "ko" ? "회원가입" : "Sign Up"}
</button>
</Link>
</>
)}
Expand Down
9 changes: 6 additions & 3 deletions my-app/src/components/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,36 @@ const LoginPage: React.FC = () => {

return (
<div className="flex flex-col items-center justify-center min-h-screen bg-stone-200">
<div className="p-8">
<form className="p-8" onSubmit={handleLogin}>
<input
className="w-full p-2 mb-4 border rounded"
type="text"
value={loginId}
onChange={(e) => setLoginId(e.target.value)}
placeholder="Login ID"
autoComplete="username"
required
/>
<input
className="w-full p-2 mb-4 border rounded"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Password"
autoComplete="username"
required
/>
<button
className={`${
isHighContrast
? "bg-yellow-300 hover:bg-yellow-600"
: "bg-[#FF6A3F] hover:bg-[#E6552F]"
} w-full p-2`}
onClick={handleLogin}
>
Login
</button>
{error && <p>{error}</p>}
</div>
</form>
</div>
);
};
Expand Down
45 changes: 25 additions & 20 deletions my-app/src/components/Messages.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
interface Messages {
[key: string]: {
fileSelectAlert: string;
uploadSuccess: (name: string) => string;
uploadFail: string;
};
}

const messages: Messages = {
ko: {
fileSelectAlert: "파일을 선택해주세요.",
uploadSuccess: (name: string) => `${name} 파일 업로드가 완료되었습니다. 변환을 시작하시겠습니까?`,
uploadFail: "파일 업로드에 실패했습니다. 다시 시도해주세요.",
},
en: {
fileSelectAlert: "Please select a file.",
uploadSuccess: (id: string) => `File ${id} has been uploaded. Would you like to start the conversion?`,
uploadFail: "File upload failed. Please try again.",
},
[key: string]: {
fileSelectAlert: string;
uploadSuccess: (name: string) => string;
uploadFail: string;
AuthFail: string;
};

export default messages;
}

const messages: Messages = {
ko: {
fileSelectAlert: "파일을 선택해주세요.",
uploadSuccess: (name: string) =>
`${name} 파일 업로드가 완료되었습니다. 변환을 시작하시겠습니까?`,
uploadFail: "파일 업로드에 실패했습니다. 다시 시도해주세요.",
AuthFail: "로그인 후 이용해 주세요.",
},
en: {
fileSelectAlert: "Please select a file.",
uploadSuccess: (id: string) =>
`File ${id} has been uploaded. Would you like to start the conversion?`,
uploadFail: "File upload failed. Please try again.",
AuthFail: "Please log in to use this service.",
},
};

export default messages;
10 changes: 5 additions & 5 deletions my-app/src/components/SignUpPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const SignUpPage: React.FC = () => {
loginId,
password,
});
if (response.status === 200) {
navigate("*");
if (response.status === 201) {
navigate("/");
}
} catch (error) {
if (axios.isAxiosError(error)) {
Expand All @@ -57,7 +57,7 @@ const SignUpPage: React.FC = () => {
<div className="flex flex-col items-center justify-center min-h-screen bg-stone-200">
<form className="p-8" onSubmit={handleSignUp}>
<input
className={`w-full p-2 mb-4 border ${
className={`${textClassName} w-full p-2 mb-4 border ${
isSubmitted && !loginId.trim() ? "border-red-500" : "rounded"
}`}
type="text"
Expand All @@ -68,7 +68,7 @@ const SignUpPage: React.FC = () => {
required
/>
<input
className={`w-full p-2 mb-4 border ${
className={`w-full p-2 mb-4 border ${textClassName} ${
isSubmitted && !password.trim() ? "border-red-500" : "rounded"
}`}
type="password"
Expand All @@ -80,7 +80,7 @@ const SignUpPage: React.FC = () => {
/>
<button
type="submit"
className={`${
className={`${textClassName} ${
isHighContrast
? "bg-yellow-300 hover:bg-yellow-600"
: "bg-[#FF6A3F] hover:bg-[#E6552F]"
Expand Down
12 changes: 8 additions & 4 deletions my-app/src/components/UploadFileButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TranslationProgress from "./TranslationProgress";
import { useLanguage } from "../LanguageContext";
import messages from "./Messages";
import { useHighContrast } from "../components/HighContrastMode";

import { useNavigate } from "react-router-dom";

interface UploadFileButtonState {
title: string;
Expand All @@ -20,9 +20,10 @@ const UploadFileButton: React.FC = () => {
const { language } = useLanguage();
const textClassName = language === "ko" ? "font-kor" : "font-eng";
const { isHighContrast } = useHighContrast();
const navigate = useNavigate();


const { fileSelectAlert, uploadSuccess, uploadFail } = messages[language];
const { fileSelectAlert, uploadSuccess, uploadFail, AuthFail } =
messages[language];
const [state, setState] = useState<UploadFileButtonState>({
title: "",
content: "",
Expand Down Expand Up @@ -82,6 +83,9 @@ const UploadFileButton: React.FC = () => {
if (confirmConversion && translationsId) {
startConversion(translationsId);
}
} else if (response.status === 401) {
alert(AuthFail);
navigate("/login");
}
} catch (error) {
alert(uploadFail);
Expand Down Expand Up @@ -154,7 +158,7 @@ const UploadFileButton: React.FC = () => {
</button>
</form>
</div>

<div>
{translationsId && (
<TranslationProgress translationsId={translationsId} />
Expand Down

0 comments on commit 7756f76

Please sign in to comment.