-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79d8a6b
commit 7b2e81e
Showing
36 changed files
with
463 additions
and
1,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use client"; | ||
|
||
import { useEffect, useId } from "react"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import Cookies from "js-cookie"; | ||
import { useForm } from "react-hook-form"; | ||
import * as z from "zod"; | ||
|
||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
} from "@acme/ui/form"; | ||
import { Switch } from "@acme/ui/switch"; | ||
|
||
const FormSchema = z.object({ | ||
weekend: z.boolean(), | ||
}); | ||
|
||
/* <WorkspaceHeader /> | ||
============================================================================= */ | ||
const WorkspaceHeader = () => { | ||
const id = useId(); | ||
const form = useForm<{ weekend: boolean }>({ | ||
resolver: zodResolver(FormSchema), | ||
defaultValues: { | ||
weekend: false, | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
const weekendCookie = JSON.parse(Cookies.get("weekend") ?? null); | ||
|
||
form.setValue("weekend", weekendCookie); | ||
}, [form]); | ||
|
||
useEffect(() => { | ||
const subscription = form.watch((value) => | ||
Cookies.set("weekend", value.weekend!.toString(), { | ||
expires: 365, | ||
}), | ||
); | ||
|
||
return () => subscription.unsubscribe(); | ||
}); | ||
return ( | ||
<div className="inline-flex items-center gap-2"> | ||
<Form {...form}> | ||
<FormLabel className="text-md uppercase">Weekends: </FormLabel> | ||
<FormField | ||
control={form.control} | ||
name="weekend" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormControl> | ||
<Switch | ||
id={`switch-${id}`} | ||
checked={field.value} | ||
onCheckedChange={field.onChange} | ||
/> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
</Form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WorkspaceHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.