Commit cb28455f authored by Darrick Yong's avatar Darrick Yong

add final touches on order details and search

parent 9d24e12b
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
.search > select { .search > select {
cursor: pointer; cursor: pointer;
border: none; padding: 10px 0;
font-size: 16px; font-size: 16px;
font-family: "Times New Roman", Times, serif; font-family: "Times New Roman", Times, serif;
} }
...@@ -106,8 +106,9 @@ ...@@ -106,8 +106,9 @@
background: #2b4162; background: #2b4162;
} }
.error { .search-select-error,
color: red; .search-input-error {
border: 2px solid #c1292e;
} }
.fs-collapse { .fs-collapse {
......
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
font-weight: 400; font-weight: 400;
font-size: 16px; font-size: 16px;
font-style: italic; font-style: italic;
width: 280px; width: 275px;
} }
.order-details-dates > div { .order-details-dates > div {
......
...@@ -40,4 +40,7 @@ q:before, q:after { ...@@ -40,4 +40,7 @@ q:before, q:after {
table { table {
border-collapse: collapse; border-collapse: collapse;
border-spacing: 0; border-spacing: 0;
}
select:focus, input:focus {
outline: none;
} }
\ No newline at end of file
const Input = ({ className, type, placeholder, value, onChange, onKeyPress }) => ( const Input = ({
<input className,
type,
placeholder,
value,
onChange,
onBlur,
onKeyPress,
}) => (
<input
type={type || "text"} type={type || "text"}
className={className} className={className}
placeholder={placeholder} placeholder={placeholder}
value={value} value={value}
onChange={onChange} onChange={onChange}
onBlur={onBlur}
onKeyPress={onKeyPress} onKeyPress={onKeyPress}
/> />
); );
......
const Select = ({ defaultVal, value, onChange, options }) => ( const Select = ({ className, defaultVal, value, onChange, options }) => (
<select <select
className={className}
value={value ? value : defaultVal} value={value ? value : defaultVal}
onChange={onChange} onChange={onChange}
> >
......
...@@ -9,14 +9,21 @@ const Search = ({ orders, setOrdersToShow, setFiltersOn }) => { ...@@ -9,14 +9,21 @@ const Search = ({ orders, setOrdersToShow, setFiltersOn }) => {
const [searchInput, setSearchInput] = useState(""); const [searchInput, setSearchInput] = useState("");
const [searchBy, setSearchBy] = useState(""); const [searchBy, setSearchBy] = useState("");
const [error, setError] = useState(""); const [error, setError] = useState("");
const [inputError, setInputError] = useState(false);
const [byError, setByError] = useState(false);
const searchOptions = ["Warehouse ID", "Order ID"]; const searchOptions = ["Warehouse ID", "Order ID"];
const search = () => { const search = () => {
if (!searchInput.length) { setInputError(false);
setError("Please enter a search parameter."); setByError(false);
if (!searchInput.length && !searchBy.length) {
setInputError(true);
setByError(true);
} else if (!searchInput.length) {
setInputError(true);
} else if (!searchBy.length) { } else if (!searchBy.length) {
setError("Please enter search method."); setByError(true);
} else { } else {
const searchResult = { allIds: [], byId: {} }; const searchResult = { allIds: [], byId: {} };
const searchedOrder = const searchedOrder =
...@@ -33,12 +40,17 @@ const Search = ({ orders, setOrdersToShow, setFiltersOn }) => { ...@@ -33,12 +40,17 @@ const Search = ({ orders, setOrdersToShow, setFiltersOn }) => {
if (searchBy.length) { if (searchBy.length) {
setOrdersToShow(searchResult); setOrdersToShow(searchResult);
} }
setError("");
setSearchInput(""); setSearchInput("");
setFiltersOn(false); setFiltersOn(false);
} }
}; };
const handleInputBlur = (e) => {
if (!e.target.value.length) {
setInputError(true);
}
}
const handleSearchEnter = (e) => { const handleSearchEnter = (e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
search(); search();
...@@ -49,21 +61,28 @@ const Search = ({ orders, setOrdersToShow, setFiltersOn }) => { ...@@ -49,21 +61,28 @@ const Search = ({ orders, setOrdersToShow, setFiltersOn }) => {
<div className="search"> <div className="search">
<div className="text">Search:</div> <div className="text">Search:</div>
<Select <Select
className={byError ? "search-select-error" : ""}
defaultVal={"Choose one.."} defaultVal={"Choose one.."}
value={searchBy} value={searchBy}
options={searchOptions} options={searchOptions}
onChange={(e) => { onChange={(e) => {
setByError(false);
setSearchBy(e.target.selectedOptions[0].value); setSearchBy(e.target.selectedOptions[0].value);
}} }}
/> />
<Input <Input
className={inputError ? "search-input-error" : ""}
placeholder={"Search by ID"} placeholder={"Search by ID"}
value={searchInput} value={searchInput}
onChange={(e) => setSearchInput(e.target.value)} onChange={(e) => {
setInputError(false);
setSearchInput(e.target.value);
}}
onBlur={handleInputBlur}
onKeyPress={handleSearchEnter} onKeyPress={handleSearchEnter}
/> />
<Button className="search-btn" text="Search" onClick={search} /> <Button className="search-btn" text="Search" onClick={search} />
{error.length ? <Error text={error}/> : null} {/* {error.length ? <Error text={error} /> : null} */}
</div> </div>
); );
}; };
......
...@@ -10,8 +10,11 @@ const OrderDetails = ({ order, showDetails }) => { ...@@ -10,8 +10,11 @@ const OrderDetails = ({ order, showDetails }) => {
const month = date.toLocaleString("default", { month: "short" }); const month = date.toLocaleString("default", { month: "short" });
const day = date.getDate(); const day = date.getDate();
const year = date.getFullYear(); const year = date.getFullYear();
const time = date.toLocaleTimeString("en-US"); const hour = date.getHours();
return `${month} ${day > 9 ? day : `0${day}`}, ${year} at ${time}`; const cHour = hour > 12 ? hour - 12 : hour;
const minute = date.getMinutes();
const time = `${cHour > 9 ? cHour : `0${cHour}`}:${minute > 9 ? minute : `0${minute}`}`;
return `${month} ${day > 9 ? day : `0${day}`}, ${year} at ${time} ${hour > 11 ? "PM" : "AM"}`;
}; };
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment