Skip to content

Commit

Permalink
Merge pull request #758 from isucon/fix-owner-default-date
Browse files Browse the repository at this point in the history
[FE] Ownerのデフォルト日時で(直近すぎて)金額が出ていない問題を修正
  • Loading branch information
narirou authored Dec 7, 2024
2 parents 768b799 + 654dc3f commit add0be7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 12 additions & 10 deletions frontend/app/contexts/owner-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { OwnerChairs, OwnerSales } from "~/types";
import { getCookieValue } from "~/utils/get-cookie-value";

type DateString = `${number}-${number}-${number}`; // YYYY-MM-DD
type DateString = `${number}-${number}-${number}`; // yyyy-mm-dd

type OwnerContextProps = Partial<{
chairs?: OwnerChairs;
Expand All @@ -43,22 +43,24 @@ const currentDateString: DateString = (() => {
return today.toISOString().slice(0, 10) as DateString;
})();

const isValidDateString = (value: string): value is DateString => {
return /\d{4}-\d{2}-\d{2}/.test(value);
};

export const OwnerProvider = ({ children }: { children: ReactNode }) => {
const [chairs, setChairs] = useState<OwnerGetChairsResponse["chairs"]>();
const [sales, setSales] = useState<OwnerGetSalesResponse>();
const navigate = useNavigate();
const [since, _setSince] = useState("2024-11-01" as DateString);
const [until, _setUntil] = useState(currentDateString);
const [since, _setSince] = useState(currentDateString);

const setUntil = useCallback((value: string) => {
if (/\d{4}-\d{2}-\d{2}/.test(value)) {
_setUntil(value as DateString);
const setSince = useCallback((value: string) => {
if (isValidDateString(value)) {
_setSince(value);
}
}, []);

const setSince = useCallback((value: string) => {
if (/\d{4}-\d{2}-\d{2}/.test(value)) {
_setSince(value as DateString);
const setUntil = useCallback((value: string) => {
if (isValidDateString(value)) {
_setUntil(value);
}
}, []);

Expand Down
1 change: 1 addition & 0 deletions frontend/app/routes/owner.sales/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DatePicker = () => {
className="w-48"
defaultValue={until}
onChange={(e) => setUntil?.(e.target.value)}
min={since}
/>
</div>
);
Expand Down

0 comments on commit add0be7

Please sign in to comment.