Skip to content

Commit

Permalink
Implement logic for getting status of domain reservation.
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalikKarpuk committed Feb 29, 2024
1 parent 10f7625 commit 2ae9a4b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
13 changes: 13 additions & 0 deletions ui/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ export async function getDomains({
);
return await res.json();
}

export async function checkReservedName(domainName: string) {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/domains/${domainName}/reserved`,
{
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.NEXT_PUBLIC_X_API_KEY,
},
}
);
return await res.json();
}
13 changes: 11 additions & 2 deletions ui/components/atoms/resultItem/resultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ import { Button } from "../button";
import { Variant } from "../button/types";
import style from "./index.module.css";

const ResultItem = ({ text, className }) => {
const ResultItem = ({
statusName,
className,
}: {
statusName: {
isReserved: boolean;
name: string;
};
className: string;
}) => {
return (
<div className={classNames(style.wrapper, className, "t-inter-medium")}>
<div>
{text}
{statusName.name}
<span>.mina</span>
</div>
<Button text="Purchase" variant={Variant.blue} />
Expand Down
22 changes: 14 additions & 8 deletions ui/components/sections/homeSection/homeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,33 @@ import { interSemiBold } from "@/app/fonts";
import { Input } from "@/components/atoms/input";
import { ResultItem } from "@/components/atoms/resultItem";
import { InputVariant } from "@/components/atoms/input/input";
import { useState } from "react";
import { useRef, useState } from "react";
import { useKeyPress } from "@/hooks/useKeyPress";
import { checkName } from "@/app/actions";
import { checkName, checkReservedName } from "@/app/actions";

const HomeSection = () => {
const [response, setResponse] = useState(null);
const [statusName, setStatusName] = useState<{
isReserved: boolean;
name: string;
}>(null);
const [value, setValue] = useState("");
const [resultContent, setResultContent] = useState({
isShow: false,
text: "",
});
const ref = useRef();

const handleInput = async () => {
const isShow = !!value;
setResultContent({
text: value,
isShow: isShow,
});
const res = await checkName(value);
const result = await res;
setResponse(result);
const response = await checkReservedName(value);
setStatusName({
isReserved: response,
name: value,
});
};

useKeyPress("Enter", handleInput);
Expand All @@ -51,8 +57,8 @@ const HomeSection = () => {
onChange={(e) => setValue(e.target.value)}
variant={InputVariant.search}
/>
{response && (
<ResultItem text={response.domainName} className={style.resultItem} />
{statusName?.name && (
<ResultItem statusName={statusName} className={style.resultItem} />
)}
</div>
</div>
Expand Down

0 comments on commit 2ae9a4b

Please sign in to comment.