Skip to content

Commit

Permalink
refactor: date & minor fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanatpakornS committed Feb 20, 2024
1 parent 721339b commit c41abfd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/admin/pets/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const adminCreate = () => {
</div>
</div>
<div className="hidden md:block">
{data && <SmallPetCardList isLoading={isLoading} pets={data.pets} />}
<SmallPetCardList isLoading={isLoading} pets={data?.pets} />
</div>
</>
);
Expand Down
7 changes: 5 additions & 2 deletions src/components/Admin/Pets/Add/DateInputInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const DateInputInfo = (props: DateInputInfoProps) => {
};

const birthdate = useMemo(() => {
return dayjs(props.value).format("MMMM DD, YYYY");
if (props.value != "-") return dayjs(props.value).format("MMMM DD, YYYY");
return "-";
}, [props.value]);

return (
Expand All @@ -40,7 +41,9 @@ const DateInputInfo = (props: DateInputInfoProps) => {
/>
</div>
) : (
<div className="ml-2 font-semibold">{birthdate}</div>
<div className="ml-2 font-semibold">
{birthdate ? birthdate : "-"}
</div>
)}
</div>
</div>
Expand Down
6 changes: 2 additions & 4 deletions src/components/Admin/Pets/Add/EditInfoAndSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import TextInputInfo from "./TextInputInfo";
import ToggleInputInfo from "./ToggleInputInfo";

export type info = {
type: string;
gender: string;
type: "dog" | "cat" | "-";
gender: "male" | "female" | "-";
color: string;
age: string;
nature: string;
Expand All @@ -37,13 +37,11 @@ const EditInfoAndSubmit = (props: EditInfoAndSubmitProps) => {
const addNoneInfo = showInfo;
if (addNoneInfo.age === "") addNoneInfo["age"] = "-";
if (addNoneInfo.nature === "") addNoneInfo["nature"] = "-";
if (addNoneInfo.gender === "") addNoneInfo["gender"] = "-";
props.setValue(addNoneInfo);
} else {
const removeEmptyInfo = props.value;
if (removeEmptyInfo.age === "-") removeEmptyInfo["age"] = "";
if (removeEmptyInfo.nature === "-") removeEmptyInfo["nature"] = "";
if (removeEmptyInfo.gender === "-") removeEmptyInfo["gender"] = "";
setShowInfo(removeEmptyInfo);
}
setEnableEdit(!enableEdit);
Expand Down

0 comments on commit c41abfd

Please sign in to comment.