-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(save-button): added a button for saving the form
- Loading branch information
1 parent
13e052c
commit f3e0efa
Showing
5 changed files
with
98 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import React, { useState } from "react"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { UseUserContext } from "@/context/User.context"; | ||
import { supabase } from "@/utils/supabase"; | ||
import { useContactStore } from "@/context/Contact.context"; | ||
import { RotatingLines } from "react-loader-spinner"; | ||
|
||
export default function DraftButton() { | ||
const [status, setStatus] = useState({ isLoading: false, isSuccess: false }); | ||
|
||
const { currentUser } = UseUserContext(); | ||
const { name, email, page } = useContactStore(); | ||
|
||
const onDraftHandler = async () => { | ||
setStatus({ isLoading: true, isSuccess: false }); | ||
await supabase.from("contact-form").upsert( | ||
{ | ||
userId: currentUser?.user.user_metadata.provider_id, | ||
email, | ||
name, | ||
page, | ||
status: "DRAFT", | ||
}, | ||
{ onConflict: "email" } | ||
); | ||
setStatus({ isLoading: false, isSuccess: true }); | ||
}; | ||
|
||
return ( | ||
<Button variant={"outline"} size={"md"} onClick={onDraftHandler}> | ||
{status.isLoading && ( | ||
<RotatingLines | ||
strokeColor="white" | ||
strokeWidth="3" | ||
animationDuration="1" | ||
width="16" | ||
visible={true} | ||
/> | ||
)} | ||
{status.isSuccess ? "Saved" : "Save"} | ||
</Button> | ||
); | ||
} |
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
f3e0efa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
portfolio – ./
alireza2015.vercel.app
portfolio-alireza1083.vercel.app
alirezasamadi.com
portfolio-git-main-alireza1083.vercel.app
www.alirezasamadi.com