Skip to content

Commit

Permalink
Merge pull request #48 from Staketab/dev
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
VitalikKarpuk authored May 2, 2024
2 parents 6afb796 + fcbe658 commit 98fd70e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
30 changes: 18 additions & 12 deletions ui/app/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,26 @@ export async function deleteName({
id,
}: {
id: string;
}): Promise<ReserveNameResponse> {
}): Promise<{ status: DATA_STATUS }> {
if (!id) return;

const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/domains/reserve/${id}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.NEXT_PUBLIC_API_KEY,
},
try {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/domains/reserve/${id}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.NEXT_PUBLIC_API_KEY,
},
}
);
if (!res.ok) {
throw new Error(`HTTP error! Status: ${res.status}`);
}
);
return await res.json();
return {
status: DATA_STATUS.SUCCESS,
};
} catch (error) {}
}

export async function changeExpirationTime(payload: {
Expand Down
4 changes: 4 additions & 0 deletions ui/components/atoms/resultItem/resultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import { DOMAIN_STATUS } from "@/comman/types";
const ResultItem = ({
statusName,
className,
clearInput,
}: {
statusName: {
id: string;
name: string;
status: DOMAIN_STATUS;
};
clearInput: () => void;

className: string;
}) => {
const { id, name, status } = statusName;
Expand Down Expand Up @@ -54,6 +57,7 @@ const ResultItem = ({
amount: response.amount,
id: response.id,
});
clearInput();
}
} catch (error) {
console.log(error);
Expand Down
10 changes: 6 additions & 4 deletions ui/components/organisms/cartContent/cartContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ const CartContent = (): JSX.Element => {
actions: { deleteFromBag, addPeriod, openModal },
} = useStoreContext();

const handleIcon = async (value: DomainForTable): Promise<void> => {
const deleteReservedName = async (value: DomainForTable): Promise<void> => {
try {
await deleteName({ id: value.id });
deleteFromBag(value?.id);
const response = await deleteName({ id: value.id });
if (response.status === DATA_STATUS.SUCCESS) {
deleteFromBag(value?.id);
}
} catch (error) {}
};

Expand All @@ -64,7 +66,7 @@ const CartContent = (): JSX.Element => {
return {
...item,
amount: Number(item.amount) * item.years * rate + " MINA",
onClick: handleIcon,
onClick: deleteReservedName,
onCount: onCount,
};
});
Expand Down
10 changes: 9 additions & 1 deletion ui/components/sections/homeSection/homeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const HomeSection = () => {
};

useKeyPress("Enter", handleInput);
const clearInput = (): void => {
setValue("");
};

const handleChange = (value) => {
const cleanInput = value.replace(/[^a-z0-9- ]/g, "");
setValue(cleanInput);
Expand Down Expand Up @@ -61,7 +65,11 @@ const HomeSection = () => {
enableClear
/>
{statusName?.name && value && (
<ResultItem statusName={statusName} className={style.resultItem} />
<ResultItem
statusName={statusName}
className={style.resultItem}
clearInput={clearInput}
/>
)}
</div>
</div>
Expand Down

0 comments on commit 98fd70e

Please sign in to comment.