Skip to content

Commit

Permalink
fix: 🐛 correct types, extract logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Jun 7, 2024
1 parent fcaf274 commit fbfdfc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/lib/components/creation/Creation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
goto(`/availability/${meetingId}`);
};
const hasValidParams = () => {
return $selectedDays.length > 0 &&
$startTime &&
$endTime &&
$startTime < $endTime &&
$meetingName
? true
: false;
};
</script>

<div class="px-4 pt-8 md:pl-[60px] md:pt-10">
Expand Down Expand Up @@ -70,13 +80,7 @@
class={cn(
"btn w-48 border-none bg-success font-montserrat text-xl font-medium text-gray-light sm:btn-wide",
)}
disabled={$selectedDays.length > 0 &&
$startTime &&
$endTime &&
$startTime < $endTime &&
$meetingName
? false
: true}
disabled={!hasValidParams()}
on:click={handleCreation}
>
Continue →
Expand Down
9 changes: 5 additions & 4 deletions src/lib/components/creation/MeetingV2/MeetingTimeField.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { startTime, endTime } from "$lib/stores/meetingSetupStores";
import type { HourMinuteString } from "$lib/types/chrono";
import { cn } from "$lib/utils/utils";
import ClockIcon from "~icons/material-symbols/nest-clock-farsight-analog-outline";
Expand All @@ -8,18 +9,18 @@
let startPeriod: "AM" | "PM" = "AM";
let endPeriod: "AM" | "PM" = "PM";
function convertTo24Hour(hour: number, period: "AM" | "PM"): string {
const convertTo24Hour = (hour: number, period: "AM" | "PM"): string => {
if (period === "PM" && hour !== 12) {
hour += 12;
} else if (period === "AM" && hour === 12) {
hour = 0;
}
return hour.toString().padStart(2, "0");
}
};
$: $startTime = `${convertTo24Hour(startHour, startPeriod)}:00` as `${string}:${string}`;
$: $endTime = `${convertTo24Hour(endHour, endPeriod)}:00` as `${string}:${string}`;
$: $startTime = `${convertTo24Hour(startHour, startPeriod)}:00` as HourMinuteString;
$: $endTime = `${convertTo24Hour(endHour, endPeriod)}:00` as HourMinuteString;
</script>

<div>
Expand Down

0 comments on commit fbfdfc7

Please sign in to comment.