-
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 #90 from Mouwf/feature/add-display-error-message-f…
…unction システムメッセージを表示する機能を追加した
- Loading branch information
Showing
75 changed files
with
1,287 additions
and
1,070 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
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,9 @@ | ||
import { createContext } from "react"; | ||
|
||
/** | ||
* システムメッセージコンテキスト。 | ||
*/ | ||
const SystemMessageContext = createContext({ | ||
showSystemMessage: (status: "success" | "error", message: string) => {} | ||
}); | ||
export default SystemMessageContext; |
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,49 @@ | ||
import SystemMessageContext from "./system-message-context"; | ||
import { ReactNode } from "react"; | ||
import toast, { Toaster, useToaster } from "react-hot-toast"; | ||
|
||
/** | ||
* システムメッセージプロバイダー。 | ||
* @param children 子要素。 | ||
* @returns システムメッセージプロバイダー。 | ||
*/ | ||
const SystemMessageProvider = ({ | ||
children, | ||
}: { | ||
children: ReactNode, | ||
}) => { | ||
const showSystemMessage = (status: "success" | "error", message: string) => { | ||
if (!message) return; | ||
switch (status) { | ||
case "success": | ||
toast.success(message); | ||
break; | ||
case "error": | ||
toast.error(message); | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<SystemMessageContext.Provider value={{ showSystemMessage }}> | ||
{children} | ||
<Toaster | ||
position="bottom-right" | ||
toastOptions={{ | ||
className: "", | ||
style: { | ||
background: "#363636", | ||
color: "#fff", | ||
}, | ||
success: { | ||
duration: 3000, | ||
}, | ||
error: { | ||
duration: 4000, | ||
}, | ||
}} | ||
/> | ||
</SystemMessageContext.Provider> | ||
); | ||
}; | ||
export default SystemMessageProvider; |
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,22 @@ | ||
import systemMessages from "../../messages/system-messages"; | ||
|
||
/** | ||
* サインアップのバリデーションを行うクラス。 | ||
*/ | ||
export default class SignUpValidator { | ||
/** | ||
* サインアップのバリデーションを行う。 | ||
* @param password パスワード。 | ||
* @param confirmPassword 再確認パスワード。 | ||
* @returns バリデーション結果。 | ||
* @throws バリデーションに失敗した場合、エラーを投げる。 | ||
*/ | ||
public static validate(password: string, confirmPassword: string): boolean { | ||
// パスワードの長さが8文字未満、英数字が含まれていない場合、エラーを投げる。 | ||
if (password.length < 8 || !password.match(/^(?=.*?[a-z])(?=.*?\d)[a-z\d]{8,100}$/i)) throw new Error(systemMessages.error.invalidPasswordOnSetting); | ||
|
||
// パスワードと再確認パスワードが一致しない場合、エラーを返す。 | ||
if (password !== confirmPassword) throw new Error(systemMessages.error.passwordMismatch); | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.