-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle unauthenticated users w/ reactions, create helper dialog…
… for logged in actions
- Loading branch information
Showing
16 changed files
with
290 additions
and
20 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,52 @@ | ||
<script setup> | ||
import { | ||
AlertDialog, | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogTitle, | ||
AlertDialogTrigger, | ||
} from '@/Components/ui/alert-dialog' | ||
import { router } from '@inertiajs/vue3'; | ||
defineProps({ | ||
action: Function | ||
}) | ||
const redirectToLogin = () => { | ||
router.visit(route('login', { | ||
redirect_to: window.location.pathname | ||
})) | ||
} | ||
</script> | ||
|
||
<template> | ||
<AlertDialog v-if="!$page.props.auth.user?.id"> | ||
<AlertDialogTrigger> | ||
<slot/> | ||
</AlertDialogTrigger> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>Must be signed in</AlertDialogTitle> | ||
<AlertDialogDescription> | ||
You must be authenticated to perform this action. Would you like to sign in? | ||
</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel> | ||
Cancel | ||
</AlertDialogCancel> | ||
<AlertDialogAction @click="redirectToLogin"> | ||
Sign In | ||
</AlertDialogAction> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
|
||
<span v-else @click.prevent="action"> | ||
<slot /> | ||
</span> | ||
</template> |
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,17 @@ | ||
<script setup> | ||
import { AlertDialogRoot, useForwardPropsEmits } from "radix-vue"; | ||
const props = defineProps({ | ||
open: { type: Boolean, required: false }, | ||
defaultOpen: { type: Boolean, required: false }, | ||
}); | ||
const emits = defineEmits(["update:open"]); | ||
const forwarded = useForwardPropsEmits(props, emits); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogRoot v-bind="forwarded"> | ||
<slot /> | ||
</AlertDialogRoot> | ||
</template> |
19 changes: 19 additions & 0 deletions
19
resources/js/Components/ui/alert-dialog/AlertDialogAction.vue
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,19 @@ | ||
<script setup> | ||
import { AlertDialogAction } from "radix-vue"; | ||
import { cn } from "@/lib/utils"; | ||
import { buttonVariants } from "@/Components/ui/button"; | ||
const props = defineProps({ | ||
asChild: { type: Boolean, required: false }, | ||
as: { type: null, required: false }, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogAction | ||
v-bind="props" | ||
:class="cn(buttonVariants(), $attrs.class ?? '')" | ||
> | ||
<slot /> | ||
</AlertDialogAction> | ||
</template> |
25 changes: 25 additions & 0 deletions
25
resources/js/Components/ui/alert-dialog/AlertDialogCancel.vue
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,25 @@ | ||
<script setup> | ||
import { AlertDialogCancel } from "radix-vue"; | ||
import { cn } from "@/lib/utils"; | ||
import { buttonVariants } from "@/Components/ui/button"; | ||
const props = defineProps({ | ||
asChild: { type: Boolean, required: false }, | ||
as: { type: null, required: false }, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogCancel | ||
v-bind="props" | ||
:class=" | ||
cn( | ||
buttonVariants({ variant: 'outline' }), | ||
'mt-2 sm:mt-0', | ||
$attrs.class ?? '' | ||
) | ||
" | ||
> | ||
<slot /> | ||
</AlertDialogCancel> | ||
</template> |
48 changes: 48 additions & 0 deletions
48
resources/js/Components/ui/alert-dialog/AlertDialogContent.vue
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,48 @@ | ||
<script setup> | ||
import { | ||
AlertDialogContent, | ||
AlertDialogOverlay, | ||
AlertDialogPortal, | ||
useEmitAsProps, | ||
} from "radix-vue"; | ||
import { cn } from "@/lib/utils"; | ||
const props = defineProps({ | ||
forceMount: { type: Boolean, required: false }, | ||
trapFocus: { type: Boolean, required: false }, | ||
disableOutsidePointerEvents: { type: Boolean, required: false }, | ||
asChild: { type: Boolean, required: false }, | ||
as: { type: null, required: false }, | ||
class: { type: String, required: false }, | ||
}); | ||
const emits = defineEmits([ | ||
"escapeKeyDown", | ||
"pointerDownOutside", | ||
"focusOutside", | ||
"interactOutside", | ||
"dismiss", | ||
"openAutoFocus", | ||
"closeAutoFocus", | ||
]); | ||
const emitsAsProps = useEmitAsProps(emits); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogPortal> | ||
<AlertDialogOverlay | ||
class="fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" | ||
/> | ||
<AlertDialogContent | ||
v-bind="{ ...props, ...emitsAsProps }" | ||
:class=" | ||
cn( | ||
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full', | ||
props.class | ||
) | ||
" | ||
> | ||
<slot /> | ||
</AlertDialogContent> | ||
</AlertDialogPortal> | ||
</template> |
19 changes: 19 additions & 0 deletions
19
resources/js/Components/ui/alert-dialog/AlertDialogDescription.vue
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,19 @@ | ||
<script setup> | ||
import { AlertDialogDescription } from "radix-vue"; | ||
import { cn } from "@/lib/utils"; | ||
const props = defineProps({ | ||
asChild: { type: Boolean, required: false }, | ||
as: { type: null, required: false }, | ||
class: { type: String, required: false }, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogDescription | ||
:class="cn('text-muted-foreground text-sm', props.class)" | ||
:as-child="props.asChild" | ||
> | ||
<slot /> | ||
</AlertDialogDescription> | ||
</template> |
23 changes: 23 additions & 0 deletions
23
resources/js/Components/ui/alert-dialog/AlertDialogFooter.vue
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,23 @@ | ||
<script setup> | ||
import { cn } from "@/lib/utils"; | ||
const props = defineProps({ | ||
class: { | ||
type: String, | ||
default: "", | ||
}, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div | ||
:class=" | ||
cn( | ||
'flex flex-col space-y-2 sm:space-y-0 mt-3.5 sm:flex-row sm:justify-end sm:space-x-2', | ||
props.class | ||
) | ||
" | ||
> | ||
<slot /> | ||
</div> | ||
</template> |
18 changes: 18 additions & 0 deletions
18
resources/js/Components/ui/alert-dialog/AlertDialogHeader.vue
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,18 @@ | ||
<script setup> | ||
import { cn } from "@/lib/utils"; | ||
const props = defineProps({ | ||
class: { | ||
type: String, | ||
default: "", | ||
}, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div | ||
:class="cn('flex flex-col space-y-2 text-center sm:text-left', props.class)" | ||
> | ||
<slot /> | ||
</div> | ||
</template> |
19 changes: 19 additions & 0 deletions
19
resources/js/Components/ui/alert-dialog/AlertDialogTitle.vue
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,19 @@ | ||
<script setup> | ||
import { AlertDialogTitle } from "radix-vue"; | ||
import { cn } from "@/lib/utils"; | ||
const props = defineProps({ | ||
asChild: { type: Boolean, required: false }, | ||
as: { type: null, required: false }, | ||
class: { type: String, required: false }, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogTitle | ||
:as-child="props.asChild" | ||
:class="cn('text-lg text-foreground font-semibold', props.class)" | ||
> | ||
<slot /> | ||
</AlertDialogTitle> | ||
</template> |
14 changes: 14 additions & 0 deletions
14
resources/js/Components/ui/alert-dialog/AlertDialogTrigger.vue
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,14 @@ | ||
<script setup> | ||
import { AlertDialogTrigger } from "radix-vue"; | ||
const props = defineProps({ | ||
asChild: { type: Boolean, required: false }, | ||
as: { type: null, required: false }, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<AlertDialogTrigger v-bind="props"> | ||
<slot /> | ||
</AlertDialogTrigger> | ||
</template> |
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,9 @@ | ||
export { default as AlertDialog } from "./AlertDialog.vue"; | ||
export { default as AlertDialogTrigger } from "./AlertDialogTrigger.vue"; | ||
export { default as AlertDialogContent } from "./AlertDialogContent.vue"; | ||
export { default as AlertDialogHeader } from "./AlertDialogHeader.vue"; | ||
export { default as AlertDialogTitle } from "./AlertDialogTitle.vue"; | ||
export { default as AlertDialogDescription } from "./AlertDialogDescription.vue"; | ||
export { default as AlertDialogFooter } from "./AlertDialogFooter.vue"; | ||
export { default as AlertDialogAction } from "./AlertDialogAction.vue"; | ||
export { default as AlertDialogCancel } from "./AlertDialogCancel.vue"; |
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