From b7e10fcd1b319ea9924b63a67d7bd7874c6612a5 Mon Sep 17 00:00:00 2001 From: Arghya Ghosh Date: Wed, 20 Oct 2021 15:21:52 +0000 Subject: [PATCH] Update homepage --- pages/index.tsx | 113 ++++++++++++++++++++++++++++------------- styles/Home.module.css | 15 +++++- 2 files changed, 92 insertions(+), 36 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 3d88491..09d6451 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,48 +1,54 @@ -import { Alert, Button, Form, Input, Layout, Typography } from 'antd'; -import axios, { AxiosError } from 'axios'; -import Head from 'next/head'; -import { useState } from 'react'; -import styles from '../styles/Home.module.css'; +import { Alert, Button, Form, Input, Layout, Typography } from "antd"; +import axios, { AxiosError } from "axios"; +import Head from "next/head"; +import { useState } from "react"; +import styles from "../styles/Home.module.css"; const { Header, Content, Footer } = Layout; const { Title } = Typography; type ShortenLinkResponse = { short_link: string; -} +}; type ShortenLinkError = { error: string; error_description: string; -} +}; type FormValues = { link: string; -} +}; export default function Home() { - const [status, setStatus] = useState<'initial' | 'error' | 'success'>('initial'); - const [message, setMessage] = useState(''); + const [status, setStatus] = useState<"initial" | "error" | "success">( + "initial" + ); + const [message, setMessage] = useState(""); const [form] = Form.useForm(); const onFinish = async ({ link }: FormValues) => { try { - const response = await axios.post('/api/shorten_link', { link }); - setStatus('success'); + const response = await axios.post( + "/api/shorten_link", + { link } + ); + setStatus("success"); setMessage(response.data?.short_link); - } - catch (e) { + } catch (e) { const error = e as AxiosError; - setStatus('error'); - setMessage(error.response?.data?.error_description || 'Something went wrong!'); + setStatus("error"); + setMessage( + error.response?.data?.error_description || "Something went wrong!" + ); } - } + }; const onFinishedFailed = () => { - setStatus('error'); - const error = form.getFieldError('link').join(' '); + setStatus("error"); + const error = form.getFieldError("link").join(" "); setMessage(error); - } + }; return ( @@ -51,8 +57,10 @@ export default function Home() {
-
@@ -60,20 +68,36 @@ export default function Home() {
+ onFinishFailed={onFinishedFailed} + >
- - + +
- @@ -81,12 +105,33 @@ export default function Home() {
Copy shortened link - {['error', 'success'].includes(status) && ()} + {["error", "success"].includes(status) && ( + + )}
- ) -} \ No newline at end of file + ); +} diff --git a/styles/Home.module.css b/styles/Home.module.css index 12cee5d..e3bbe3f 100644 --- a/styles/Home.module.css +++ b/styles/Home.module.css @@ -16,6 +16,12 @@ min-height: calc(100vh - 64px - 70px); } +@media only screen and (max-width: 400px) { + .content { + padding: 0 20px; + } +} + .shortner { width: 100%; background: #fff; @@ -32,12 +38,17 @@ .linkFieldInput { flex: 100%; margin-right: 5px; + border-radius: 20px; } .linkFieldButton { width: 120px; } +.submitButton:hover { + box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1); +} + .footer { background: #001529; text-align: center; @@ -47,5 +58,5 @@ color: #00dd9b; } .link:hover { - color:#ff7875; -} \ No newline at end of file + color: #ff7875; +}