From bb20c1b5776d1e6ceb4e46e3a32981829da6709a Mon Sep 17 00:00:00 2001 From: Ajay-Dhangar Date: Wed, 11 Sep 2024 06:09:26 +0530 Subject: [PATCH] Debug code --- courses/github/clone-a-repository.md | 2 +- courses/github/commit-changes.md | 57 +++++++++++++++++ src/pages/contact/index.tsx | 91 ++++++++++++++++++++-------- 3 files changed, 125 insertions(+), 25 deletions(-) diff --git a/courses/github/clone-a-repository.md b/courses/github/clone-a-repository.md index f89f5660f..a1a2e3074 100644 --- a/courses/github/clone-a-repository.md +++ b/courses/github/clone-a-repository.md @@ -77,4 +77,4 @@ To clone a repository from GitHub, follow these steps: # Push changes back to GitHub ``` -Congratulations! You have successfully cloned a repository from GitHub to your local machine. You can now start working on the project, collaborate with others, and contribute to the codebase. Happy coding! 🚀 \ No newline at end of file +Congratulations! You have successfully cloned a repository from GitHub to your local machine. You can now start working on the project, collaborate with others, and contribute to the codebase. Happy coding! \ No newline at end of file diff --git a/courses/github/commit-changes.md b/courses/github/commit-changes.md index e69de29bb..240117f0d 100644 --- a/courses/github/commit-changes.md +++ b/courses/github/commit-changes.md @@ -0,0 +1,57 @@ +--- +id: commit-changes +title: Commit Changes +sidebar_label: Commit Changes +sidebar_position: 7 +description: Learn how to commit changes to a Git repository using Git. Commit your changes, add a commit message, and keep track of your project history with Git commits. +tags: [github, git, version control, collaboration, beginners] +keywords: [github, git, version control, collaboration, beginners, open source, commit, changes, history, project] +--- + +**To save your changes to a Git repository, you need to commit them. Committing changes creates a snapshot of your project at a specific point in time, allowing you to track the history of your project and collaborate with others.** + +To commit changes to a Git repository, follow these steps: + +1. Open your terminal or command prompt on your local machine. Navigate to the directory of your Git repository using the `cd` command. + + ```bash title="Terminal" + cd path/to/repository + ``` + +2. Check the status of your repository to see which files have changed. Use the `git status` command to view the changes that are not yet staged for commit. + + ```bash title="Terminal" + git status + ``` + + The `git status` command will show you the files that have been modified, added, or deleted since the last commit. + +3. Stage the changes you want to commit using the `git add` command. This command adds the changes to the staging area, preparing them for the next commit. + + ```bash title="Terminal" + git add filename + ``` + + :::tip Note: + Replace `filename` with the name of the file you want to stage. You can also use `git add .` to stage all changes in the repository. + ::: + +4. Commit the changes using the `git commit` command. This command creates a new commit with the changes you staged in the previous step. + + ```bash title="Terminal" + git commit -m "Add new feature to the project" + ``` + + :::tip Note: + Replace `"Add new feature to the project"` with a meaningful commit message that describes the changes you made in this commit. + ::: + +5. Verify the commit by checking the commit history of your repository. Use the `git log` command to view the commit history, including the commit message, author, date, and commit hash. + + ```bash title="Terminal" + git log + ``` + + The `git log` command will display a list of commits in reverse chronological order, showing the most recent commits first. + +6. Congratulations! You have successfully committed changes to your Git repository. Your project history is now updated with the new commit, and you can continue working on your project with confidence. \ No newline at end of file diff --git a/src/pages/contact/index.tsx b/src/pages/contact/index.tsx index bc8d1c529..25d7d8398 100644 --- a/src/pages/contact/index.tsx +++ b/src/pages/contact/index.tsx @@ -58,32 +58,75 @@ export default function Contact(): JSX.Element { }; // Function to handle form submission - const handleSubmit = async(e: FormEvent) => { + const handleSubmit = async (e: FormEvent) => { e.preventDefault(); - setChecker(pre=>({...pre,loading:true})) - let response=await axios.post("https://chh-backend.vercel.app/contact",{ - name:formValues.fullName, - email:formValues.email, - message:formValues.message - }) - - setFormValues({ - fullName: "", - email: "", - phone: "", - message: "", - feedbackType: "Question", - otherFeedback: "", - }) - if(response.data.ok){ - setChecker(pre=>({...pre,popup:true,status:true,loading:false})) - } - else{ - setChecker(pre=>({...pre,popup:true,status:false,loading:false})) + + setChecker((prev) => ({ ...prev, loading: true })); + + try { + // Sending form data to the backend with correct headers + const response = await axios.post( + "https://chh-backend.vercel.app/email-contact", + { + name: formValues.fullName, + email: formValues.email, + phone: formValues.phone, + message: formValues.message, + feedbackType: formValues.feedbackType, + otherFeedback: formValues.otherFeedback, + }, + { + headers: { + "Content-Type": "application/json", // Ensuring JSON format + }, + } + ); + + // Resetting form values after submission + setFormValues({ + fullName: "", + email: "", + phone: "", + message: "", + feedbackType: "Question", + otherFeedback: "", + }); + + // Handling response based on the server's reply + if (response.data.ok) { + setChecker((prev) => ({ + ...prev, + popup: true, + status: true, + loading: false, + })); + } else { + setChecker((prev) => ({ + ...prev, + popup: true, + status: false, + loading: false, + })); + } + } catch (error) { + console.error("Error submitting the form:", error); + // Set error state if request fails + setChecker((prev) => ({ + ...prev, + popup: true, + status: false, + loading: false, + })); } - setTimeout(()=>{ - setChecker(pre=>({...pre,popup:false,status:false})) - },2000) + + // Hide popup after 2 seconds + setTimeout(() => { + setChecker((prev) => ({ + ...prev, + popup: false, + status: false, + })); + }, 2000); }; return (