-
Notifications
You must be signed in to change notification settings - Fork 0
feat(arc): hide calendar event button #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GTR1701
wants to merge
8
commits into
main
Choose a base branch
from
feat/arc-hide-event
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f93267e
feat(arc): hide calendar event button
GTR1701 85de50c
chore(arc): minor logic fixes
GTR1701 e2d64f6
fix(arc): label closing
GTR1701 a600ffe
chore(arc): extract hidden event param to a constant
GTR1701 247e43e
fix(arc): revert param type change
GTR1701 2f5d105
chore(resources): fetchResources refactor
GTR1701 3f2cda8
chore(arc): change show/hide event button type
GTR1701 e815e46
chore(arc): search params types
GTR1701 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
147 changes: 147 additions & 0 deletions
147
src/features/abstract-resource-calendar/components/arc-hide-button-with-dialog.tsx
This file contains hidden or 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,147 @@ | ||
| "use client"; | ||
|
|
||
| import { useQueryClient } from "@tanstack/react-query"; | ||
| import type { VariantProps } from "class-variance-authority"; | ||
| import { Eye, EyeOff } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { toast } from "sonner"; | ||
|
|
||
| import { | ||
| AlertDialog, | ||
| AlertDialogAction, | ||
| AlertDialogCancel, | ||
| AlertDialogContent, | ||
| AlertDialogDescription, | ||
| AlertDialogFooter, | ||
| AlertDialogHeader, | ||
| AlertDialogTitle, | ||
| AlertDialogTrigger, | ||
| } from "@/components/ui/alert-dialog"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import type { buttonVariants } from "@/components/ui/button/variants"; | ||
| import { fetchMutation, getKey, useMutationWrapper } from "@/features/backend"; | ||
| import type { MessageResponse } from "@/features/backend/types"; | ||
| import { GrammaticalCase, declineNoun } from "@/features/polish"; | ||
| import type { Resource } from "@/features/resources"; | ||
| import { useRouter } from "@/hooks/use-router"; | ||
| import { getToastMessages } from "@/lib/get-toast-messages"; | ||
| import type { OptionalPromise } from "@/types/helpers"; | ||
| import { quoteText } from "@/utils"; | ||
|
|
||
| export function ArcHideButtonWithDialog({ | ||
| resource, | ||
| googleCalId, | ||
| hidden, | ||
| itemName, | ||
| showLabel = false, | ||
| onHideSuccess, | ||
| ...props | ||
| }: { | ||
| resource: Resource; | ||
| googleCalId: string; | ||
| hidden: boolean; | ||
| itemName?: string; | ||
| showLabel?: boolean; | ||
| onHideSuccess?: () => OptionalPromise<boolean>; | ||
| } & VariantProps<typeof buttonVariants>) { | ||
| const [isAlertDialogOpen, setIsAlertDialogOpen] = useState(false); | ||
| const router = useRouter(); | ||
| const queryClient = useQueryClient(); | ||
| const { mutateAsync, isPending } = useMutationWrapper< | ||
| MessageResponse, | ||
| string | ||
| >(getKey.mutation.hideResource(resource, googleCalId), async (calId) => { | ||
| const response = await fetchMutation<MessageResponse>(`hidden`, { | ||
| resource, | ||
| method: "POST", | ||
| body: { googleCalId: calId, hide: !hidden }, | ||
| }); | ||
|
GTR1701 marked this conversation as resolved.
|
||
| setIsAlertDialogOpen(false); | ||
| await queryClient.invalidateQueries({ | ||
| queryKey: [getKey.query.resourceList(resource)], | ||
| exact: false, | ||
| }); | ||
| if ((await onHideSuccess?.()) !== false) { | ||
| router.refresh(); | ||
| } | ||
| return response; | ||
| }); | ||
|
|
||
| function handleHide() { | ||
| toast.promise( | ||
| mutateAsync(googleCalId), | ||
| getToastMessages.resource(resource).modify, | ||
|
GTR1701 marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
|
||
| const declensions = declineNoun(resource); | ||
| const label = hidden | ||
| ? `Pokaż ${declensions.accusative}` | ||
| : `Ukryj ${declensions.accusative}`; | ||
|
|
||
| return ( | ||
| <AlertDialog open={isAlertDialogOpen} onOpenChange={setIsAlertDialogOpen}> | ||
| <AlertDialogTrigger asChild> | ||
| <Button | ||
| variant="icon" | ||
| size={showLabel ? "sm" : "icon"} | ||
| aria-label={label} | ||
| tooltip={showLabel ? undefined : label} | ||
| {...props} | ||
| > | ||
| {showLabel ? label : null} | ||
| {hidden ? <Eye /> : <EyeOff />} | ||
| </Button> | ||
| </AlertDialogTrigger> | ||
| <AlertDialogContent | ||
| onCloseAutoFocus={(event) => { | ||
| event.preventDefault(); | ||
| }} | ||
| > | ||
|
GTR1701 marked this conversation as resolved.
GTR1701 marked this conversation as resolved.
GTR1701 marked this conversation as resolved.
|
||
| <AlertDialogHeader> | ||
| <AlertDialogTitle className="text-balance"> | ||
| {hidden | ||
| ? "Czy na pewno chcesz pokazać" | ||
| : "Czy na pewno chcesz ukryć"}{" "} | ||
| { | ||
| itemName == null | ||
| ? declineNoun(resource, { | ||
| case: GrammaticalCase.Accusative, | ||
| prependDeterminer: "this", | ||
| }) // e.g. tę organizację studencką | ||
| : `${declensions.accusative} ${quoteText(itemName)}` // e.g. organizację studencką „KN Solvro” | ||
| } | ||
| ? | ||
| </AlertDialogTitle> | ||
| <AlertDialogDescription> | ||
| {hidden | ||
| ? "Wydarzenie zostanie ponownie wyświetlone w kalendarzu." | ||
| : "Wydarzenie zostanie ukryte w kalendarzu."} | ||
| </AlertDialogDescription> | ||
| </AlertDialogHeader> | ||
| <AlertDialogFooter> | ||
| <AlertDialogCancel>Anuluj</AlertDialogCancel> | ||
| <AlertDialogAction asChild> | ||
| <Button | ||
| variant={hidden ? "default" : "destructive"} | ||
| onClick={handleHide} | ||
| loading={isPending} | ||
| > | ||
| {hidden ? ( | ||
| <> | ||
| <Eye /> | ||
| Pokaż | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <EyeOff /> | ||
| Ukryj | ||
| </> | ||
| )} | ||
| </Button> | ||
| </AlertDialogAction> | ||
| </AlertDialogFooter> | ||
| </AlertDialogContent> | ||
| </AlertDialog> | ||
| ); | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| export const CALENDAR_MAX_EVENTS_PER_DAY = 5; | ||
|
|
||
| export const WEEKDAYS = ["Pn", "Wt", "Śr", "Cz", "Pt", "So", "Nd"]; | ||
|
|
||
| export const HIDDEN_EVENT_QUERY_PARAMS: Record<string, string> = { | ||
| showHidden: "true", | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.