Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

feat: Added Transition for better question submit flow #253

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/QuestionSubmissionForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// import { useState } from 'react';
import '../pages/questions/transition.module.css';
import { type SubmitHandler, useForm, FieldValues } from 'react-hook-form';
import type { PageProps } from '../lib/types';
import { useState } from 'react';

interface QuestionSubmissionFormInputs {
company: string;
Expand All @@ -15,6 +18,7 @@ export function QuestionSubmissionForm({ session }: PageProps) {
// reference: https://react-hook-form.com/get-started#Quickstart
const { register, handleSubmit, reset, formState } = useForm<QuestionSubmissionFormInputs>();

const [loading, setLoading] = useState(false);
const onSubmit: SubmitHandler<FieldValues> = async data => {
console.log(data);

Expand All @@ -36,6 +40,10 @@ export function QuestionSubmissionForm({ session }: PageProps) {
} catch (err) {
console.log(err);
}
setLoading(true);
setTimeout(() => {
setLoading(false);
}, 5000);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ykdojo if you think 5000 value is bit more we can reduce it


console.log(result);

Expand Down Expand Up @@ -176,6 +184,12 @@ export function QuestionSubmissionForm({ session }: PageProps) {
</div>
</div>
</form>
{loading && (
<div className='spinner-wrapper'>
<div className='spinner'></div>
</div>
)}
{/* {submitMessage && <div>Submit another Question</div>} */}
</div>
);
}
62 changes: 62 additions & 0 deletions src/pages/questions/transition.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.spinner-wrapper {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
background-color: rgb(255, 255, 255);
z-index: 9999;
}
.spinner {
position: absolute;
left: 50%;
top: 50%;
height: 60px;
width: 60px;
margin: 0px auto;
-webkit-animation: rotation 0.6s infinite linear;
-moz-animation: rotation 0.6s infinite linear;
-o-animation: rotation 0.6s infinite linear;
animation: rotation 0.6s infinite linear;
border-left: 6px solid rgba(0, 174, 239, 0.15);
border-right: 6px solid rgba(0, 174, 239, 0.15);
border-bottom: 6px solid rgba(0, 174, 239, 0.15);
border-top: 6px solid rgba(0, 174, 239, 0.8);
border-radius: 100%;
}

@-webkit-keyframes rotation {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
}
}
@-moz-keyframes rotation {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(359deg);
}
}
@-o-keyframes rotation {
from {
-o-transform: rotate(0deg);
}
to {
-o-transform: rotate(359deg);
}
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
64 changes: 64 additions & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,67 @@
#__next {
min-height: 100%;
}
@layer components {
.spinner-wrapper {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
background-color: rgb(255, 255, 255);
z-index: 9999;
}
.spinner {
position: absolute;
left: 50%;
top: 50%;
height: 60px;
width: 60px;
margin: 0px auto;
-webkit-animation: rotation 0.6s infinite linear;
-moz-animation: rotation 0.6s infinite linear;
-o-animation: rotation 0.6s infinite linear;
animation: rotation 0.6s infinite linear;
border-left: 6px solid rgba(0, 174, 239, 0.15);
border-right: 6px solid rgba(0, 174, 239, 0.15);
border-bottom: 6px solid rgba(0, 174, 239, 0.15);
border-top: 6px solid rgba(0, 174, 239, 0.8);
border-radius: 100%;
}

@-webkit-keyframes rotation {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
}
}
@-moz-keyframes rotation {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(359deg);
}
}
@-o-keyframes rotation {
from {
-o-transform: rotate(0deg);
}
to {
-o-transform: rotate(359deg);
}
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
}