From 72e313c2c68efff5f844ce123c1651ea33a8e331 Mon Sep 17 00:00:00 2001 From: Ambuj Raj Date: Wed, 28 Feb 2024 00:35:23 +0530 Subject: [PATCH] added feedback implementation --- main.tf | 12 +++ middleware/main.py | 32 ++++++- ui/package-lock.json | 120 +++++++++++++++++++++++++++ ui/src/app/(pages)/feedback/page.tsx | 11 --- ui/src/components/header.tsx | 108 +++++++++++++++++++++--- ui/src/components/ui/textarea.tsx | 24 ++++++ 6 files changed, 282 insertions(+), 25 deletions(-) delete mode 100644 ui/src/app/(pages)/feedback/page.tsx create mode 100644 ui/src/components/ui/textarea.tsx diff --git a/main.tf b/main.tf index 0e004c8..c3dc2b2 100644 --- a/main.tf +++ b/main.tf @@ -93,6 +93,18 @@ resource "aws_dynamodb_table" "byteshare-user" { } } +resource "aws_dynamodb_table" "byteshare-feedback" { + provider = aws.aws + name = "byteshare-feedback" + billing_mode = "PAY_PER_REQUEST" + hash_key = "feedback_id" + + attribute { + name = "feedback_id" + type = "S" + } +} + resource "aws_dynamodb_table" "byteshare-subscriber" { provider = aws.aws name = "byteshare-subscriber" diff --git a/middleware/main.py b/middleware/main.py index 2104199..24fb375 100644 --- a/middleware/main.py +++ b/middleware/main.py @@ -39,9 +39,11 @@ table_name = "byteshare-upload-metadata" user_table_name = "byteshare-user" subscriber_table_name = "byteshare-subscriber" +feedback_table_name = "byteshare-feedback" dynamodb = DynamoDBManager(table_name) user_dynamodb = DynamoDBManager(user_table_name) subscriber_dynamodb = DynamoDBManager(subscriber_table_name) +feedback_dynamodb = DynamoDBManager(feedback_table_name) class StatusEnum(PythonEnum): @@ -74,6 +76,11 @@ class AddUser(BaseModel): registration: str email: str +class Feedback(BaseModel): + name: str + email: str + message: str + @app.get("/health") def health_check(): @@ -319,6 +326,29 @@ def post_upload_return_link_qr(body: PostUpload, upload_id: str): "downloads_allowed": str(upload_metadata["max_download"]), } +@app.post("/feedback") +def post_feedback(body: Feedback): + """ + Add feedback received from users to DB + + Parameters: + - name: name of the user + - email: email address of user + - message: feedback + + + Returns: + - None + """ + + feedback = { + "feedback_id": uuid.uuid4().hex, + "email": body.email, + "name": body.name, + "message": body.message + } + feedback_dynamodb.create_item(feedback) + @app.post("/user") def webhook_post_user_send_email(body: AddUser): @@ -356,7 +386,7 @@ def webhook_post_user_send_email(body: AddUser):

We established ByteShare to make file sharing easy, hassle-free and secure.

-

I’d love to hear what you think of our product. Is there anything we should work on or improve? Let us know.

+

I’d love to hear what you think of our product. Is there anything we should work on or improve? Let us know.

You can also star us on Github

I'm always happy to help and read our customers' suggestions.

diff --git a/ui/package-lock.json b/ui/package-lock.json index 3b0be4d..9de3bbf 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -6504,6 +6504,126 @@ "funding": { "url": "https://github.com/sponsors/colinhacks" } + }, + "node_modules/@next/swc-darwin-arm64": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.4.tgz", + "integrity": "sha512-mF05E/5uPthWzyYDyptcwHptucf/jj09i2SXBPwNzbgBNc+XnwzrL0U6BmPjQeOL+FiB+iG1gwBeq7mlDjSRPg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.4.tgz", + "integrity": "sha512-VwwZKrBQo/MGb1VOrxJ6LrKvbpo7UbROuyMRvQKTFKhNaXjUmKTu7wxVkIuCARAfiI8JpaWAnKR+D6tzpCcM4w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.4.tgz", + "integrity": "sha512-8QftwPEW37XxXoAwsn+nXlodKWHfpMaSvt81W43Wh8dv0gkheD+30ezWMcFGHLI71KiWmHK5PSQbTQGUiidvLQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.4.tgz", + "integrity": "sha512-/s/Pme3VKfZAfISlYVq2hzFS8AcAIOTnoKupc/j4WlvF6GQ0VouS2Q2KEgPuO1eMBwakWPB1aYFIA4VNVh667A==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.4.tgz", + "integrity": "sha512-m8z/6Fyal4L9Bnlxde5g2Mfa1Z7dasMQyhEhskDATpqr+Y0mjOBZcXQ7G5U+vgL22cI4T7MfvgtrM2jdopqWaw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.4.tgz", + "integrity": "sha512-7Wv4PRiWIAWbm5XrGz3D8HUkCVDMMz9igffZG4NB1p4u1KoItwx9qjATHz88kwCEal/HXmbShucaslXCQXUM5w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.4.tgz", + "integrity": "sha512-zLeNEAPULsl0phfGb4kdzF/cAVIfaC7hY+kt0/d+y9mzcZHsMS3hAS829WbJ31DkSlVKQeHEjZHIdhN+Pg7Gyg==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "14.0.4", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.4.tgz", + "integrity": "sha512-yEh2+R8qDlDCjxVpzOTEpBLQTEFAcP2A8fUFLaWNap9GitYKkKv1//y2S6XY6zsR4rCOPRpU7plYDR+az2n30A==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/ui/src/app/(pages)/feedback/page.tsx b/ui/src/app/(pages)/feedback/page.tsx deleted file mode 100644 index 260889d..0000000 --- a/ui/src/app/(pages)/feedback/page.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react' - -function FeedbackPage() { - return ( -
-

Coming Soon

-
- ) -} - -export default FeedbackPage diff --git a/ui/src/components/header.tsx b/ui/src/components/header.tsx index 2730dad..9041a01 100644 --- a/ui/src/components/header.tsx +++ b/ui/src/components/header.tsx @@ -1,9 +1,17 @@ -import Link from 'next/link' import { useRouter } from 'next/navigation' -import React, { useEffect } from 'react' +import { toast } from 'sonner' +import React, { useEffect, useState } from 'react' import { Button } from './ui/button' +import { Popover, PopoverContent, PopoverTrigger } from './ui/popover' +import { Label } from './ui/label' +import { Input } from './ui/input' +import { Textarea } from './ui/textarea' export const Header = ({ authorised, statusLoaded }) => { + const [feedbackName, setFeedbackName] = useState('') + const [feedbackEmail, setFeedbackEmail] = useState('') + const [feedbackMessage, setFeedbackMessage] = useState('') + const [popoverOpen, setPopoverOpen] = useState(false) const router = useRouter() useEffect(() => { const script = document.createElement('script') @@ -15,6 +23,29 @@ export const Header = ({ authorised, statusLoaded }) => { document.body.removeChild(script) } }, []) + + const handleFeedbackSubmit = async (event) => { + event.preventDefault() + setPopoverOpen(false) + + const apiBaseURL = process.env.NEXT_PUBLIC_API_BASE_URL + const feedbackJSON = { + name: feedbackName, + email: feedbackEmail, + message: feedbackMessage, + } + + await fetch(apiBaseURL + '/feedback', { + method: 'POST', + body: JSON.stringify(feedbackJSON), + headers: { + 'Content-Type': 'application/json', + }, + }) + + toast.success('Your feedback has been received.😃') + } + return (