Skip to content

Commit

Permalink
Merge pull request #4 from chinweibegbu/1-visual-request-state-indicator
Browse files Browse the repository at this point in the history
Loading State Visual Indicators
  • Loading branch information
chinweibegbu authored Sep 18, 2024
2 parents 822daf8 + 7309d05 commit a863949
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 100 deletions.
49 changes: 49 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-hook-form": "^7.52.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.25.1",
"react-toastify": "^10.0.5",
"yup": "^1.4.0"
},
"devDependencies": {
Expand Down
Binary file added public/illustration-sitting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/no-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Signup from "./pages/signup";
import Dashboard from "./pages/dashboard";
import ResetUser from './pages/resetUser';
import ResetPassword from './pages/resetPassword';
import { NotifyContainer } from './utils/notifications';

function App() {

Expand All @@ -20,6 +21,8 @@ function App() {

return (
<div className='App min-h-screen'>

<NotifyContainer />
<Header goToPage={goToPage} />

<Container>
Expand Down
19 changes: 16 additions & 3 deletions src/components/AddTaskModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { useForm, SubmitHandler } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";

import { toggleModal } from "../../store/modalsSlice";
import { addTask, fetchTasksByUserId } from "../../store/tasksSlice";
import { AppDispatch } from "../../store/store";
import { AppDispatch, RootState } from "../../store/store";
import { AddTaskFormSchema } from "../../schemas";
import { AddTaskFormValues } from "../../models";

import Button from "../Button";
import ButtonWithLoader from "../ButtonWithLoader";
import { notifyError } from "../../utils/notifications";

// ---------------------- END IMPORTS ---------------------------------

function AddTaskModal() {

const dispatch = useDispatch<AppDispatch>();
const { loading } = useSelector((state: RootState) => state.tasksReducer);

const {
handleSubmit,
Expand All @@ -35,6 +38,11 @@ function AddTaskModal() {
// Close Add Task modal
dispatch(toggleModal({ modalName: "addTaskModal", showModal: false }));
}

if (response.type === "addTask/rejected") {
// Toggle error toast
notifyError("Error while adding task");
}
});
}

Expand Down Expand Up @@ -71,7 +79,12 @@ function AddTaskModal() {

{/* "Add Task" button */}
<div className="w-full text-center pt-4">
<Button text="Add Task" />
{
(loading)
? <ButtonWithLoader text="Adding Task"/>
: <Button text="Add Task" />
}

</div>

</form>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ButtonProps } from "../../models";
function Button({ text, handleClick, isDelete }: ButtonProps) {
return (
<button
className={"font-tabular font-medium text-regular py-2 px-6 rounded-md" + (
className={"Button font-tabular font-medium text-regular py-2 px-6 rounded-md" + (
(!isDelete)
? " border-4 border-green bg-green text-neutral-100 hover:bg-green-dark hover:border-green-dark"
: " border-4 border-red-light bg-red-light text-neutral-100 hover:bg-red-dark hover:border-red-dark"
Expand Down
2 changes: 1 addition & 1 deletion src/components/ButtonWithIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ButtonWithIconsProps } from "../../models";
function ButtonWithIcons({ text, iconClass, handleClick }: ButtonWithIconsProps) {
return (
<button
className="font-tabular font-medium text-regular px-4 rounded-md text-neutral-100 bg-green-light hover:bg-green active:bg-green-dark flex items-center"
className="ButtonWithIcons font-tabular font-medium text-regular px-4 rounded-md text-neutral-100 bg-green-light hover:bg-green active:bg-green-dark flex items-center"
onClick={handleClick}
type="submit">
<i className={"bi-" + iconClass + " text-icon-large mr-4"} />
Expand Down
22 changes: 22 additions & 0 deletions src/components/ButtonWithLoader/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ButtonWithLoaderProps } from "../../models";

function ButtonWithLoader({ text, isDelete }: ButtonWithLoaderProps) {
return (
<button
className={"Button flex gap-2 mx-auto items-center font-tabular font-medium text-regular py-2 px-6 rounded-md" + (
(!isDelete)
? " border-4 border-green bg-green text-neutral-100 hover:bg-green-dark hover:border-green-dark disabled:bg-green-light disabled:border-green-light"
: " border-4 border-red-light bg-red-light text-neutral-100 hover:bg-red-dark hover:border-red-dark disabled:bg-red-light disabled:border-red-light"
)}
disabled
type="submit" >
<svg aria-hidden="true" className="size-4 animate-spin fill-neutral-0" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor" />
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill" />
</svg>
{text}
</button >
);
}

export default ButtonWithLoader;
Loading

0 comments on commit a863949

Please sign in to comment.