Fixed creation of users + better frontend handling of permissions
This commit is contained in:
@@ -2,15 +2,21 @@ package shortcodes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"fr.latosa-escrima/core"
|
"fr.latosa-escrima/core"
|
||||||
"fr.latosa-escrima/core/models"
|
"fr.latosa-escrima/core/models"
|
||||||
|
"fr.latosa-escrima/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleShortcodes(w http.ResponseWriter, r *http.Request) {
|
func HandleShortcodes(w http.ResponseWriter, r *http.Request) {
|
||||||
var shortcodes []models.Shortcode
|
var shortcodes []models.Shortcode
|
||||||
err := core.DB.NewSelect().Model(&shortcodes).Scan(context.Background())
|
err := core.DB.NewSelect().
|
||||||
|
Model(&shortcodes).
|
||||||
|
Relation("Media").
|
||||||
|
Scan(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.JSONError{
|
core.JSONError{
|
||||||
Status: core.Error,
|
Status: core.Error,
|
||||||
@@ -19,6 +25,26 @@ func HandleShortcodes(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheme := "http"
|
||||||
|
if r.TLS != nil || os.Getenv("ENVIRONMENT") != "DEV" { // Check if the request is over HTTPS
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the host
|
||||||
|
host := r.Host
|
||||||
|
baseURL := fmt.Sprintf("%s://%s", scheme, host)
|
||||||
|
if os.Getenv("ENVIRONMENT") != "DEV" {
|
||||||
|
baseURL += "/api"
|
||||||
|
}
|
||||||
|
shortcodes = utils.Map(shortcodes, func(s models.Shortcode) models.Shortcode {
|
||||||
|
if s.MediaID == nil {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
s.Media.Author = nil
|
||||||
|
s.Media.URL = fmt.Sprintf("%s/media/%s/file", baseURL, s.MediaID)
|
||||||
|
return s
|
||||||
|
})
|
||||||
|
|
||||||
core.JSONSuccess{
|
core.JSONSuccess{
|
||||||
Status: core.Success,
|
Status: core.Success,
|
||||||
Message: "Shortcodes retrieved.",
|
Message: "Shortcodes retrieved.",
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import (
|
|||||||
|
|
||||||
core "fr.latosa-escrima/core"
|
core "fr.latosa-escrima/core"
|
||||||
"fr.latosa-escrima/core/models"
|
"fr.latosa-escrima/core/models"
|
||||||
|
"fr.latosa-escrima/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleNew(w http.ResponseWriter, r *http.Request) {
|
func HandleNew(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := context.Background()
|
||||||
var user models.User
|
var user models.User
|
||||||
err := json.NewDecoder(r.Body).Decode(&user)
|
err := json.NewDecoder(r.Body).Decode(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -22,15 +24,8 @@ func HandleNew(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
log.Println("User : ", user)
|
log.Println("User : ", user)
|
||||||
|
|
||||||
res, err := user.Insert(core.DB, context.Background())
|
res, err := user.Insert(core.DB, ctx)
|
||||||
log.Println(res)
|
log.Println(res)
|
||||||
// if res == nil {
|
|
||||||
// core.JSONError{
|
|
||||||
// Status: core.Error,
|
|
||||||
// Message: "The user couldn't be inserted.",
|
|
||||||
// }.Respond(w, http.StatusNotAcceptable)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.JSONError{
|
core.JSONError{
|
||||||
@@ -40,6 +35,24 @@ func HandleNew(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userRoles := utils.Map(user.Roles, func(role models.Role) models.UserToRole {
|
||||||
|
return models.UserToRole{
|
||||||
|
UserID: user.UserID,
|
||||||
|
RoleID: role.ID,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, userRole := range userRoles {
|
||||||
|
_, err := core.DB.NewInsert().Model(&userRole).Ignore().Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
core.JSONSuccess{
|
core.JSONSuccess{
|
||||||
Status: core.Success,
|
Status: core.Success,
|
||||||
Message: "User inserted successfully.",
|
Message: "User inserted successfully.",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,6 +12,9 @@ import (
|
|||||||
|
|
||||||
"fr.latosa-escrima/core"
|
"fr.latosa-escrima/core"
|
||||||
"fr.latosa-escrima/core/models"
|
"fr.latosa-escrima/core/models"
|
||||||
|
"fr.latosa-escrima/utils"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateUserArgs struct {
|
type UpdateUserArgs struct {
|
||||||
@@ -20,9 +24,11 @@ type UpdateUserArgs struct {
|
|||||||
Password *string `json:"password,omitempty"`
|
Password *string `json:"password,omitempty"`
|
||||||
Phone *string `json:"phone,omitempty"`
|
Phone *string `json:"phone,omitempty"`
|
||||||
Attributes *models.UserAttributes `json:"attributes"`
|
Attributes *models.UserAttributes `json:"attributes"`
|
||||||
|
Roles *[]models.Role `json:"roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := context.Background()
|
||||||
var updateArgs UpdateUserArgs
|
var updateArgs UpdateUserArgs
|
||||||
err := json.NewDecoder(r.Body).Decode(&updateArgs)
|
err := json.NewDecoder(r.Body).Decode(&updateArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -33,13 +39,34 @@ func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user_uuid := r.PathValue("user_uuid")
|
||||||
|
uid, err := uuid.Parse(user_uuid)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
var user models.User
|
var user models.User
|
||||||
|
err = core.DB.
|
||||||
|
NewSelect().
|
||||||
|
Model(&user).
|
||||||
|
Where("user_id = ?", user_uuid).
|
||||||
|
Relation("Roles").
|
||||||
|
Scan(ctx)
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
updateQuery := core.DB.NewUpdate().Model(&user)
|
updateQuery := core.DB.NewUpdate().Model(&user)
|
||||||
|
|
||||||
|
rolesInsert := []*bun.InsertQuery{}
|
||||||
|
rolesRemoved := []*bun.DeleteQuery{}
|
||||||
|
|
||||||
val := reflect.ValueOf(updateArgs)
|
val := reflect.ValueOf(updateArgs)
|
||||||
typ := reflect.TypeOf(updateArgs)
|
typ := reflect.TypeOf(updateArgs)
|
||||||
|
|
||||||
for i := 0; i < val.NumField(); i++ {
|
for i := range val.NumField() {
|
||||||
field := val.Field(i)
|
field := val.Field(i)
|
||||||
fieldname := typ.Field(i).Name
|
fieldname := typ.Field(i).Name
|
||||||
|
|
||||||
@@ -52,6 +79,37 @@ func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
if field.IsValid() && !field.IsNil() && !field.IsZero() {
|
if field.IsValid() && !field.IsNil() && !field.IsZero() {
|
||||||
if fieldname == "Password" {
|
if fieldname == "Password" {
|
||||||
updateQuery.Set(fmt.Sprintf("%s = crypt(?, gen_salt('bf'))", strings.Split(tag, ",")[0]), field.Interface())
|
updateQuery.Set(fmt.Sprintf("%s = crypt(?, gen_salt('bf'))", strings.Split(tag, ",")[0]), field.Interface())
|
||||||
|
} else if fieldname == "Roles" {
|
||||||
|
_roles := field.Interface().(*[]models.Role)
|
||||||
|
if _roles == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
currentRoles := utils.Map(user.Roles, func(role models.Role) uuid.UUID {
|
||||||
|
return role.ID
|
||||||
|
})
|
||||||
|
|
||||||
|
roles := utils.Map(*_roles, func(role models.Role) uuid.UUID {
|
||||||
|
return role.ID
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Println(user.Roles)
|
||||||
|
toAdd, toRemove := utils.GetDiff(currentRoles, roles)
|
||||||
|
fmt.Println(toAdd, toRemove)
|
||||||
|
|
||||||
|
rolesInsert = utils.Map(toAdd, func(id uuid.UUID) *bun.InsertQuery {
|
||||||
|
userRole := models.UserToRole{
|
||||||
|
UserID: uid,
|
||||||
|
RoleID: id,
|
||||||
|
}
|
||||||
|
return core.DB.NewInsert().Model(&userRole).Ignore()
|
||||||
|
})
|
||||||
|
|
||||||
|
rolesRemoved = utils.Map(toRemove, func(id uuid.UUID) *bun.DeleteQuery {
|
||||||
|
return core.DB.NewDelete().Model((*models.UserToRole)(nil)).
|
||||||
|
Where("user_id = ? AND role_id = ?", uid, id)
|
||||||
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
updateQuery.Set(fmt.Sprintf("%s = ?", strings.Split(tag, ",")[0]), field.Interface())
|
updateQuery.Set(fmt.Sprintf("%s = ?", strings.Split(tag, ",")[0]), field.Interface())
|
||||||
}
|
}
|
||||||
@@ -61,11 +119,9 @@ func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Always update the `updated_at` field
|
// Always update the `updated_at` field
|
||||||
updateQuery.Set("updated_at = ?", time.Now())
|
updateQuery.Set("updated_at = ?", time.Now())
|
||||||
|
|
||||||
uuid := r.PathValue("user_uuid")
|
|
||||||
_, err = updateQuery.
|
_, err = updateQuery.
|
||||||
Where("user_id = ?", uuid).
|
Where("user_id = ?", user_uuid).
|
||||||
Returning("*").
|
Exec(ctx)
|
||||||
Exec(context.Background())
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.JSONError{
|
core.JSONError{
|
||||||
@@ -75,6 +131,28 @@ func HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, insert := range rolesInsert {
|
||||||
|
_, err = insert.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, remove := range rolesRemoved {
|
||||||
|
_, err = remove.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
core.JSONError{
|
||||||
|
Status: core.Error,
|
||||||
|
Message: err.Error(),
|
||||||
|
}.Respond(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user.Password = ""
|
user.Password = ""
|
||||||
|
|
||||||
core.JSONSuccess{
|
core.JSONSuccess{
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ func HandleUsers(w http.ResponseWriter, r *http.Request) {
|
|||||||
var users []models.User
|
var users []models.User
|
||||||
count, err := core.DB.NewSelect().
|
count, err := core.DB.NewSelect().
|
||||||
Model(&users).
|
Model(&users).
|
||||||
|
Order("created_at ASC").
|
||||||
Relation("Roles").
|
Relation("Roles").
|
||||||
ScanAndCount(context.Background())
|
ScanAndCount(context.Background())
|
||||||
|
|
||||||
|
|||||||
42
backend/utils/get_diff.go
Normal file
42
backend/utils/get_diff.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetDiff returns two slices: elements to add and elements to remove
|
||||||
|
func GetDiff[T comparable](current, newm []T) ([]T, []T) {
|
||||||
|
log.Println(current, newm)
|
||||||
|
// Use a single map with an int to track state:
|
||||||
|
// 1: only in current, 2: only in new, 3: in both
|
||||||
|
presence := make(map[T]int)
|
||||||
|
|
||||||
|
// Mark all items in current as 1
|
||||||
|
for _, item := range current {
|
||||||
|
presence[item] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update map based on newm: add 2 if not present, set to 3 if present
|
||||||
|
for _, item := range newm {
|
||||||
|
if val, exists := presence[item]; exists {
|
||||||
|
presence[item] = val + 2 // 1 -> 3 (both)
|
||||||
|
} else {
|
||||||
|
presence[item] = 2 // only in new
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var toAdd, toRemove []T
|
||||||
|
|
||||||
|
// Iterate once over the map to build results
|
||||||
|
for item, state := range presence {
|
||||||
|
switch state {
|
||||||
|
case 1: // Only in current -> remove
|
||||||
|
toRemove = append(toRemove, item)
|
||||||
|
case 2: // Only in new -> add
|
||||||
|
toAdd = append(toAdd, item)
|
||||||
|
// case 3: in both, do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toAdd, toRemove
|
||||||
|
}
|
||||||
@@ -48,9 +48,9 @@ export default function BlogTable({ user }: { user: IUser }) {
|
|||||||
|
|
||||||
const { replace } = useRouter();
|
const { replace } = useRouter();
|
||||||
|
|
||||||
const canUpdate = hasPermissions(user.roles, { blogs: ["update"] });
|
const { blogs: blogsPerm } = hasPermissions(user.roles, {
|
||||||
const canInsert = hasPermissions(user.roles, { blogs: ["insert"] });
|
blogs: ["update", "insert", "delete"],
|
||||||
const canDelete = hasPermissions(user.roles, { blogs: ["delete"] });
|
} as const);
|
||||||
|
|
||||||
const updateSearchParam = useCallback(
|
const updateSearchParam = useCallback(
|
||||||
(key: string, value?: string) => {
|
(key: string, value?: string) => {
|
||||||
@@ -136,7 +136,7 @@ export default function BlogTable({ user }: { user: IUser }) {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{canInsert && (
|
{blogsPerm.insert && (
|
||||||
<Button asChild>
|
<Button asChild>
|
||||||
<Link href="/dashboard/blogs/new">Nouvel article</Link>
|
<Link href="/dashboard/blogs/new">Nouvel article</Link>
|
||||||
</Button>
|
</Button>
|
||||||
@@ -151,7 +151,7 @@ export default function BlogTable({ user }: { user: IUser }) {
|
|||||||
<TableHead>Catégorie</TableHead>
|
<TableHead>Catégorie</TableHead>
|
||||||
<TableHead>Auteur</TableHead>
|
<TableHead>Auteur</TableHead>
|
||||||
<TableHead>Publié</TableHead>
|
<TableHead>Publié</TableHead>
|
||||||
{(canUpdate || canDelete) && (
|
{(blogsPerm.update || blogsPerm.delete) && (
|
||||||
<TableHead className="w-[100px]">
|
<TableHead className="w-[100px]">
|
||||||
Actions
|
Actions
|
||||||
</TableHead>
|
</TableHead>
|
||||||
@@ -175,7 +175,7 @@ export default function BlogTable({ user }: { user: IUser }) {
|
|||||||
"MMM d, yyyy",
|
"MMM d, yyyy",
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
{(canDelete || canUpdate) && (
|
{(blogsPerm.delete || blogsPerm.update) && (
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
@@ -190,7 +190,7 @@ export default function BlogTable({ user }: { user: IUser }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{canUpdate && (
|
{blogsPerm.update && (
|
||||||
<DropdownMenuItem asChild>
|
<DropdownMenuItem asChild>
|
||||||
<Link
|
<Link
|
||||||
href={`/dashboard/blogs/${blog.blogID}`}
|
href={`/dashboard/blogs/${blog.blogID}`}
|
||||||
@@ -201,7 +201,7 @@ export default function BlogTable({ user }: { user: IUser }) {
|
|||||||
</Link>
|
</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
)}
|
)}
|
||||||
{canDelete && (
|
{blogsPerm.delete && (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
className="flex items-center text-destructive focus:text-destructive"
|
className="flex items-center text-destructive focus:text-destructive"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|||||||
16
frontend/app/(auth)/dashboard/blogs/new/_new.tsx
Normal file
16
frontend/app/(auth)/dashboard/blogs/new/_new.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
|
const BlogEditor = dynamic(
|
||||||
|
() => import("@/components/article/edit").then((mod) => mod.default),
|
||||||
|
{
|
||||||
|
ssr: false,
|
||||||
|
loading: () => <Loader2 className="animate-spin" />,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export default function NewBlog() {
|
||||||
|
return <BlogEditor />;
|
||||||
|
}
|
||||||
@@ -1,16 +1,21 @@
|
|||||||
"use client";
|
"use server";
|
||||||
|
import getMe from "@/lib/getMe";
|
||||||
|
import hasPermissions from "@/lib/hasPermissions";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import NewBlog from "./_new";
|
||||||
|
|
||||||
import { Loader2 } from "lucide-react";
|
export default async function Page() {
|
||||||
import dynamic from "next/dynamic";
|
const me = await getMe();
|
||||||
|
if (
|
||||||
|
!me ||
|
||||||
|
me.status === "Error" ||
|
||||||
|
!me.data ||
|
||||||
|
!hasPermissions(me.data.roles, {
|
||||||
|
blogs: ["insert"],
|
||||||
|
} as const).all
|
||||||
|
) {
|
||||||
|
redirect("/dashboard");
|
||||||
|
}
|
||||||
|
|
||||||
const BlogEditor = dynamic(
|
return <NewBlog />;
|
||||||
() => import("@/components/article/edit").then((mod) => mod.default),
|
|
||||||
{
|
|
||||||
ssr: false,
|
|
||||||
loading: () => <Loader2 className="animate-spin" />,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export default function Page() {
|
|
||||||
return <BlogEditor />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export default async function Page() {
|
|||||||
me.status === "Error" ||
|
me.status === "Error" ||
|
||||||
!me.data ||
|
!me.data ||
|
||||||
!hasPermissions(me.data.roles, {
|
!hasPermissions(me.data.roles, {
|
||||||
blogs: ["get"],
|
blogs: ["get"] as const,
|
||||||
})
|
}).all
|
||||||
) {
|
) {
|
||||||
redirect("/dashboard");
|
redirect("/dashboard");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,238 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { UserIcon, Building, X } from "lucide-react";
|
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { Role, User } from "@/types/types";
|
|
||||||
import { useParams } from "next/navigation";
|
|
||||||
import { useApi } from "@/hooks/use-api";
|
|
||||||
import { useState } from "react";
|
|
||||||
import request from "@/lib/request";
|
|
||||||
import IUser from "@/interfaces/IUser";
|
|
||||||
import hasPermissions from "@/lib/hasPermissions";
|
|
||||||
|
|
||||||
export default function UserDetailsPage({ user }: { user: IUser }) {
|
|
||||||
const { uuid } = useParams<{ uuid: string }>();
|
|
||||||
const _user = useApi<User>(`/users/${uuid}`, {}, true);
|
|
||||||
|
|
||||||
const availableRoles = useApi<Role[]>("/roles", {}, true);
|
|
||||||
availableRoles.data ??= [];
|
|
||||||
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
|
||||||
// const [selectedOrg, setSelectedOrg] = useState("");
|
|
||||||
|
|
||||||
const addRole = async (role: Role) => {
|
|
||||||
const res = await request(
|
|
||||||
`/users/${_user.data?.userId}/roles/${role.id}/add`,
|
|
||||||
{ method: "PATCH", requiresAuth: true },
|
|
||||||
);
|
|
||||||
if (res.status === "Success") {
|
|
||||||
setSelectedRole(null);
|
|
||||||
_user.mutate();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeRole = async (role: Role) => {
|
|
||||||
const res = await request(
|
|
||||||
`/users/${_user.data?.userId}/roles/${role.id}/remove`,
|
|
||||||
{ method: "PATCH", requiresAuth: true },
|
|
||||||
);
|
|
||||||
if (res.status === "Success") _user.mutate();
|
|
||||||
};
|
|
||||||
|
|
||||||
const addOrganization = () => {
|
|
||||||
// if (selectedOrg && !user.organizations.includes(selectedOrg)) {
|
|
||||||
// setUser((prevUser) => ({
|
|
||||||
// ...prevUser,
|
|
||||||
// organizations: [...prevUser.organizations, selectedOrg],
|
|
||||||
// }));
|
|
||||||
// setSelectedOrg("");
|
|
||||||
// }
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeOrganization = (orgToRemove: string) => {
|
|
||||||
// setUser((prevUser) => ({
|
|
||||||
// ...prevUser,
|
|
||||||
// organizations: prevUser.organizations.filter(
|
|
||||||
// (org) => org !== orgToRemove,
|
|
||||||
// ),
|
|
||||||
// }));
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!_user.data || !_user.success) return <p>Error</p>;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="container mx-auto py-10">
|
|
||||||
<Card>
|
|
||||||
<CardContent className="pt-6">
|
|
||||||
<div className="grid gap-6">
|
|
||||||
<div className="flex items-center space-x-4">
|
|
||||||
<UserIcon className="h-12 w-12 text-gray-400" />
|
|
||||||
<div>
|
|
||||||
<h2 className="text-xl font-semibold">
|
|
||||||
{_user.data.firstname} {_user.data.lastname}
|
|
||||||
</h2>
|
|
||||||
<p className="text-sm text-gray-500">
|
|
||||||
{_user.data.email}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-6 md:grid-cols-2">
|
|
||||||
<div>
|
|
||||||
<h3 className="text-lg font-semibold mb-2">
|
|
||||||
Rôles
|
|
||||||
</h3>
|
|
||||||
<div className="flex flex-wrap gap-2">
|
|
||||||
{_user.data.roles?.map((role) => (
|
|
||||||
<Badge
|
|
||||||
key={role.id}
|
|
||||||
variant="secondary"
|
|
||||||
className="text-sm py-1 px-2"
|
|
||||||
>
|
|
||||||
{role.name}
|
|
||||||
{hasPermissions(user.roles, {
|
|
||||||
users: ["update"],
|
|
||||||
}) && (
|
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
removeRole(role)
|
|
||||||
}
|
|
||||||
className="ml-2 text-gray-500 hover:text-gray-700"
|
|
||||||
>
|
|
||||||
<X className="h-3 w-3" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</Badge>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{hasPermissions(user.roles, {
|
|
||||||
users: ["update"],
|
|
||||||
}) && (
|
|
||||||
<div className="mt-2 flex space-x-2">
|
|
||||||
<Select
|
|
||||||
value={
|
|
||||||
selectedRole
|
|
||||||
? selectedRole.name
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
onValueChange={(s) => {
|
|
||||||
const r =
|
|
||||||
availableRoles.data?.find(
|
|
||||||
(r) => r.name === s,
|
|
||||||
);
|
|
||||||
console.log(r);
|
|
||||||
if (r) setSelectedRole(r);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-[180px]">
|
|
||||||
<SelectValue placeholder="Sélectionner un rôle" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{availableRoles.data
|
|
||||||
.filter(
|
|
||||||
(org) =>
|
|
||||||
!_user.data?.roles?.includes(
|
|
||||||
org,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.map((role) => (
|
|
||||||
<SelectItem
|
|
||||||
key={role.id}
|
|
||||||
value={role.name}
|
|
||||||
>
|
|
||||||
{role.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<Button
|
|
||||||
disabled={
|
|
||||||
!_user.data || !selectedRole
|
|
||||||
}
|
|
||||||
onClick={() =>
|
|
||||||
addRole(selectedRole!)
|
|
||||||
}
|
|
||||||
className="flex items-center"
|
|
||||||
>
|
|
||||||
<Building className="mr-2 h-4 w-4" />
|
|
||||||
Ajouter le rôle
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/*<div>
|
|
||||||
<h3 className="text-lg font-semibold mb-2">
|
|
||||||
Organizations
|
|
||||||
</h3>
|
|
||||||
<div className="flex flex-wrap gap-2">
|
|
||||||
{user.data.organizations.map((org) => (
|
|
||||||
<Badge
|
|
||||||
key={org}
|
|
||||||
variant="outline"
|
|
||||||
className="text-sm py-1 px-2"
|
|
||||||
>
|
|
||||||
{org}
|
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
removeOrganization(org)
|
|
||||||
}
|
|
||||||
className="ml-2 text-gray-500 hover:text-gray-700"
|
|
||||||
>
|
|
||||||
<X className="h-3 w-3" />
|
|
||||||
</button>
|
|
||||||
</Badge>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div className="mt-2 flex space-x-2">
|
|
||||||
<Select
|
|
||||||
value={selectedOrg}
|
|
||||||
onValueChange={setSelectedOrg}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-[180px]">
|
|
||||||
<SelectValue placeholder="Select an organization" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{availableOrganizations
|
|
||||||
.filter(
|
|
||||||
(org) =>
|
|
||||||
!user.organizations.includes(
|
|
||||||
org,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.map((org) => (
|
|
||||||
<SelectItem
|
|
||||||
key={org}
|
|
||||||
value={org}
|
|
||||||
>
|
|
||||||
{org}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<Button
|
|
||||||
onClick={addOrganization}
|
|
||||||
className="flex items-center"
|
|
||||||
>
|
|
||||||
<Building className="mr-2 h-4 w-4" />
|
|
||||||
Add Org
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div> */}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import getMe from "@/lib/getMe";
|
|
||||||
import hasPermissions from "@/lib/hasPermissions";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import UserDetailsPage from "./_user";
|
|
||||||
|
|
||||||
export default async function Page() {
|
|
||||||
const me = await getMe();
|
|
||||||
if (
|
|
||||||
!me ||
|
|
||||||
me.status === "Error" ||
|
|
||||||
!me.data ||
|
|
||||||
!hasPermissions(me.data.roles, {
|
|
||||||
users: ["get"],
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
redirect("/dashboard");
|
|
||||||
}
|
|
||||||
|
|
||||||
return <UserDetailsPage user={me.data} />;
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ export default async function Page({}) {
|
|||||||
!me.data ||
|
!me.data ||
|
||||||
!hasPermissions(me.data.roles, {
|
!hasPermissions(me.data.roles, {
|
||||||
users: ["get"],
|
users: ["get"],
|
||||||
})
|
} as const).all
|
||||||
) {
|
) {
|
||||||
redirect("/dashboard");
|
redirect("/dashboard");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ export default function PlanningPage({ user }: { user: IUser }) {
|
|||||||
if (success)
|
if (success)
|
||||||
return (
|
return (
|
||||||
<Planning
|
<Planning
|
||||||
modifiable={hasPermissions(user.roles, {
|
modifiable={
|
||||||
|
hasPermissions(user.roles, {
|
||||||
events: ["update", "insert", "delete"],
|
events: ["update", "insert", "delete"],
|
||||||
})}
|
} as const).all
|
||||||
|
}
|
||||||
events={requestedEvents ?? []}
|
events={requestedEvents ?? []}
|
||||||
mutate={mutate}
|
mutate={mutate}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default async function Page() {
|
|||||||
!me.data ||
|
!me.data ||
|
||||||
!hasPermissions(me.data.roles, {
|
!hasPermissions(me.data.roles, {
|
||||||
events: ["get"],
|
events: ["get"],
|
||||||
})
|
} as const).all
|
||||||
) {
|
) {
|
||||||
redirect("/dashboard");
|
redirect("/dashboard");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default async function Page() {
|
|||||||
!me ||
|
!me ||
|
||||||
me.status === "Error" ||
|
me.status === "Error" ||
|
||||||
!me.data ||
|
!me.data ||
|
||||||
!hasPermissions(me.data.roles, { media: ["get"] })
|
!hasPermissions(me.data.roles, { media: ["get"] } as const).all
|
||||||
) {
|
) {
|
||||||
redirect("/dashboard");
|
redirect("/dashboard");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ export default function RolesAndPermissions({ user }: { user: IUser }) {
|
|||||||
const [newRoleName, setNewRoleName] = useState<string>("");
|
const [newRoleName, setNewRoleName] = useState<string>("");
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);
|
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const { roles: rolesPerm } = hasPermissions(user.roles, {
|
||||||
|
roles: ["insert"],
|
||||||
|
} as const);
|
||||||
|
|
||||||
const { data: permissions } = useApi<PermissionsGrouped>(
|
const { data: permissions } = useApi<PermissionsGrouped>(
|
||||||
"/permissions/grouped",
|
"/permissions/grouped",
|
||||||
{},
|
{},
|
||||||
@@ -80,7 +84,7 @@ export default function RolesAndPermissions({ user }: { user: IUser }) {
|
|||||||
<div className="container mx-auto p-4 space-y-6">
|
<div className="container mx-auto p-4 space-y-6">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<h1 className="text-2xl font-bold">Rôles et Permissions</h1>
|
<h1 className="text-2xl font-bold">Rôles et Permissions</h1>
|
||||||
{hasPermissions(user.roles, { roles: ["insert"] }) && (
|
{rolesPerm.insert && (
|
||||||
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button>
|
<Button>
|
||||||
@@ -135,14 +139,17 @@ interface RoleCardProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function RoleCard({ role, onDelete, permissions, user }: RoleCardProps) {
|
function RoleCard({ role, onDelete, permissions, user }: RoleCardProps) {
|
||||||
|
const { roles, permissions: permPerms } = hasPermissions(user.roles, {
|
||||||
|
roles: ["delete", "update"],
|
||||||
|
permissions: ["update"],
|
||||||
|
} as const);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle>{toTitleCase(role.name)}</CardTitle>
|
<CardTitle>{toTitleCase(role.name)}</CardTitle>
|
||||||
<Button
|
<Button
|
||||||
disabled={
|
disabled={!roles.delete}
|
||||||
!hasPermissions(user.roles, { roles: ["delete"] })
|
|
||||||
}
|
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={onDelete}
|
onClick={onDelete}
|
||||||
@@ -155,10 +162,11 @@ function RoleCard({ role, onDelete, permissions, user }: RoleCardProps) {
|
|||||||
return (
|
return (
|
||||||
<ResourceSection
|
<ResourceSection
|
||||||
disabled={
|
disabled={
|
||||||
!hasPermissions(user.roles, {
|
!(roles.update && permPerms.update)
|
||||||
permissions: ["update"],
|
// !hasPermissions(user.roles, {
|
||||||
roles: ["update"],
|
// permissions: ["update"],
|
||||||
})
|
// roles: ["update"],
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
key={res}
|
key={res}
|
||||||
resource={res}
|
resource={res}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default async function Page() {
|
|||||||
!hasPermissions(me.data.roles, {
|
!hasPermissions(me.data.roles, {
|
||||||
roles: ["get"],
|
roles: ["get"],
|
||||||
permissions: ["get"],
|
permissions: ["get"],
|
||||||
})
|
} as const).all
|
||||||
) {
|
) {
|
||||||
redirect("/dashboard");
|
redirect("/dashboard");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default async function Page() {
|
|||||||
!me.data ||
|
!me.data ||
|
||||||
!hasPermissions(me.data.roles, {
|
!hasPermissions(me.data.roles, {
|
||||||
shortcodes: ["get"],
|
shortcodes: ["get"],
|
||||||
})
|
} as const).all
|
||||||
) {
|
) {
|
||||||
redirect("/dashboard");
|
redirect("/dashboard");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ export default async function Home() {
|
|||||||
})}
|
})}
|
||||||
</Gallery>
|
</Gallery>
|
||||||
)}
|
)}
|
||||||
<Testimonial />
|
{/*<Testimonial />*/}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
pointer-events: auto !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
@@ -82,6 +83,7 @@ body {
|
|||||||
* {
|
* {
|
||||||
@apply border-border outline-ring/50;
|
@apply border-border outline-ring/50;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import "@/lib/utils";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Geist, Geist_Mono } from "next/font/google";
|
import { Geist, Geist_Mono } from "next/font/google";
|
||||||
import "@/app/globals.css";
|
import "@/app/globals.css";
|
||||||
|
|||||||
13
frontend/app/robots.ts
Normal file
13
frontend/app/robots.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { BASE_URL } from "@/lib/constants";
|
||||||
|
import type { MetadataRoute } from "next";
|
||||||
|
|
||||||
|
export default function robots(): MetadataRoute.Robots {
|
||||||
|
return {
|
||||||
|
rules: {
|
||||||
|
userAgent: "*",
|
||||||
|
allow: "/",
|
||||||
|
disallow: ["/dashboard/", "/gallery/"],
|
||||||
|
},
|
||||||
|
sitemap: `${BASE_URL}/sitemap.xml`,
|
||||||
|
};
|
||||||
|
}
|
||||||
43
frontend/app/sitemap.ts
Normal file
43
frontend/app/sitemap.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { BASE_URL } from "@/lib/constants";
|
||||||
|
import type { MetadataRoute } from "next";
|
||||||
|
|
||||||
|
export default function sitemap(): MetadataRoute.Sitemap {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
url: BASE_URL,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "yearly",
|
||||||
|
priority: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: `${BASE_URL}/about`,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "monthly",
|
||||||
|
priority: 0.8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: `${BASE_URL}/blog`,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "weekly",
|
||||||
|
priority: 0.5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: `${BASE_URL}/planning`,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "daily",
|
||||||
|
priority: 0.8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: `${BASE_URL}/gallery`,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "daily",
|
||||||
|
priority: 0.8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: `${BASE_URL}/contact`,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "yearly",
|
||||||
|
priority: 0.8,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -13,8 +13,10 @@ const BlogArticle: React.FC<{ blog: Blog; user?: IUser }> = ({
|
|||||||
blog,
|
blog,
|
||||||
user,
|
user,
|
||||||
}) => {
|
}) => {
|
||||||
|
const perms =
|
||||||
|
user && hasPermissions(user.roles, { blogs: ["update"] } as const);
|
||||||
const UpdateButton = () => {
|
const UpdateButton = () => {
|
||||||
if (!user || !hasPermissions(user.roles, { blogs: ["update"] })) return;
|
if (!perms?.blogs.update) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button variant="secondary">
|
<Button variant="secondary">
|
||||||
|
|||||||
@@ -11,14 +11,10 @@ import {
|
|||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
} from "@/components/ui/alert-dialog";
|
} from "@/components/ui/alert-dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Loader2, Trash2 } from "lucide-react";
|
import { Trash2 } from "lucide-react";
|
||||||
import { useState } from "react";
|
|
||||||
import hasPermissions from "@/lib/hasPermissions";
|
import hasPermissions from "@/lib/hasPermissions";
|
||||||
import IUser from "@/interfaces/IUser";
|
import IUser from "@/interfaces/IUser";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import request from "@/lib/request";
|
import request from "@/lib/request";
|
||||||
import { ApiResponse } from "@/types/types";
|
|
||||||
|
|
||||||
interface DeleteArticleButtonProps {
|
interface DeleteArticleButtonProps {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -29,7 +25,9 @@ const DeleteArticleButton: React.FC<DeleteArticleButtonProps> = ({
|
|||||||
id,
|
id,
|
||||||
user,
|
user,
|
||||||
}) => {
|
}) => {
|
||||||
if (!user || !hasPermissions(user.roles, { blogs: ["update"] })) {
|
const perms =
|
||||||
|
user && hasPermissions(user.roles, { blogs: ["delete"] } as const);
|
||||||
|
if (!perms?.blogs.delete) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import {
|
|||||||
AlignLeft,
|
AlignLeft,
|
||||||
AlignRight,
|
AlignRight,
|
||||||
Bold,
|
Bold,
|
||||||
Code,
|
|
||||||
Code2,
|
|
||||||
Heading1,
|
Heading1,
|
||||||
Heading2,
|
Heading2,
|
||||||
Heading3,
|
Heading3,
|
||||||
@@ -43,10 +41,14 @@ import {
|
|||||||
TooltipProvider,
|
TooltipProvider,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
|
import {
|
||||||
import { Label } from "./ui/label";
|
Popover,
|
||||||
import { Input } from "./ui/input";
|
PopoverContent,
|
||||||
import { Switch } from "./ui/switch";
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -55,12 +57,27 @@ import {
|
|||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "./ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
|
|
||||||
|
import { SizeOption } from "./extensions/marks";
|
||||||
|
|
||||||
interface EditorMenuProps {
|
interface EditorMenuProps {
|
||||||
editor: Editor | null;
|
editor: Editor | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sizeOptions: SizeOption[] = ["xs", "sm", "base", "lg", "xl"];
|
||||||
|
const tailwindColors = [
|
||||||
|
{ value: "default", label: "Default" }, // Changed from '' to "default"
|
||||||
|
{ value: "gray-500", label: "Gray" },
|
||||||
|
{ value: "red-500", label: "Red" },
|
||||||
|
{ value: "yellow-500", label: "Yellow" },
|
||||||
|
{ value: "green-500", label: "Green" },
|
||||||
|
{ value: "blue-500", label: "Blue" },
|
||||||
|
{ value: "indigo-500", label: "Indigo" },
|
||||||
|
{ value: "purple-500", label: "Purple" },
|
||||||
|
{ value: "pink-500", label: "Pink" },
|
||||||
|
];
|
||||||
|
|
||||||
export function EditorMenu({ editor }: EditorMenuProps) {
|
export function EditorMenu({ editor }: EditorMenuProps) {
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
return null;
|
return null;
|
||||||
@@ -70,6 +87,7 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
<TooltipProvider delayDuration={0}>
|
<TooltipProvider delayDuration={0}>
|
||||||
<div className="flex flex-wrap gap-2 rounded-t-lg border bg-background p-1">
|
<div className="flex flex-wrap gap-2 rounded-t-lg border bg-background p-1">
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{/* Existing formatting toggles */}
|
||||||
<ToggleGroup
|
<ToggleGroup
|
||||||
type="multiple"
|
type="multiple"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -154,30 +172,82 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>Strikethrough</TooltipContent>
|
<TooltipContent>Strikethrough</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<ToggleGroupItem
|
|
||||||
value="code"
|
|
||||||
aria-label="Toggle code"
|
|
||||||
aria-selected={editor.isActive("code")}
|
|
||||||
onClick={() =>
|
|
||||||
editor
|
|
||||||
.chain()
|
|
||||||
.focus()
|
|
||||||
.toggleCode()
|
|
||||||
.run()
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Code className="h-4 w-4" />
|
|
||||||
</ToggleGroupItem>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>Code</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</ToggleGroup>
|
</ToggleGroup>
|
||||||
|
|
||||||
<Separator orientation="vertical" className="h-8" />
|
<Separator orientation="vertical" className="h-8" />
|
||||||
|
|
||||||
|
{/* Font Size Selector */}
|
||||||
|
<Select
|
||||||
|
value={
|
||||||
|
editor.isActive("fontSize")
|
||||||
|
? editor.getAttributes("fontSize").size ||
|
||||||
|
"base"
|
||||||
|
: "base"
|
||||||
|
}
|
||||||
|
onValueChange={(value: SizeOption) => {
|
||||||
|
editor
|
||||||
|
.chain()
|
||||||
|
.focus()
|
||||||
|
.setFontSize({ size: value })
|
||||||
|
.run();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="h-8 w-[100px]">
|
||||||
|
<SelectValue placeholder="Size" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
{sizeOptions.map((size) => (
|
||||||
|
<SelectItem key={size} value={size}>
|
||||||
|
{size.toUpperCase()}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
{/* Text Color Selector */}
|
||||||
|
{/*<Select
|
||||||
|
value={
|
||||||
|
editor.isActive("textColor")
|
||||||
|
? editor.getAttributes("textColor").color ||
|
||||||
|
"default"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
if (value === "default") {
|
||||||
|
editor.chain().focus().unsetTextColor().run();
|
||||||
|
} else {
|
||||||
|
editor
|
||||||
|
.chain()
|
||||||
|
.focus()
|
||||||
|
.setTextColor({ color: value })
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="h-8 w-[100px]">
|
||||||
|
<SelectValue placeholder="Color" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
{tailwindColors.map(({ value, label }) => (
|
||||||
|
<SelectItem key={value} value={value}>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className={`h-3 w-3 rounded-full ${value === "default" ? "bg-gray-200" : `bg-${value}`}`}
|
||||||
|
/>
|
||||||
|
{label}
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select> */}
|
||||||
|
|
||||||
|
<Separator orientation="vertical" className="h-8" />
|
||||||
|
|
||||||
|
{/* Heading Selector */}
|
||||||
<Select
|
<Select
|
||||||
value={getActiveHeading(editor)}
|
value={getActiveHeading(editor)}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
@@ -229,6 +299,7 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
|
|
||||||
<Separator orientation="vertical" className="h-8" />
|
<Separator orientation="vertical" className="h-8" />
|
||||||
|
|
||||||
|
{/* Alignment Controls */}
|
||||||
<ToggleGroup
|
<ToggleGroup
|
||||||
type="single"
|
type="single"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -324,6 +395,7 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
|
|
||||||
<Separator orientation="vertical" className="h-8" />
|
<Separator orientation="vertical" className="h-8" />
|
||||||
|
|
||||||
|
{/* List and Blockquote Controls */}
|
||||||
<ToggleGroup
|
<ToggleGroup
|
||||||
type="multiple"
|
type="multiple"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -373,26 +445,6 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
<TooltipContent>Ordered list</TooltipContent>
|
<TooltipContent>Ordered list</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<ToggleGroupItem
|
|
||||||
value="codeBlock"
|
|
||||||
aria-label="Toggle code block"
|
|
||||||
aria-pressed={editor.isActive("codeBlock")}
|
|
||||||
onClick={() =>
|
|
||||||
editor
|
|
||||||
.chain()
|
|
||||||
.focus()
|
|
||||||
.toggleCodeBlock()
|
|
||||||
.run()
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Code2 className="h-4 w-4" />
|
|
||||||
</ToggleGroupItem>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>Code block</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
|
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<ToggleGroupItem
|
<ToggleGroupItem
|
||||||
@@ -418,6 +470,7 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
|
|
||||||
<Separator orientation="vertical" className="h-8" />
|
<Separator orientation="vertical" className="h-8" />
|
||||||
|
|
||||||
|
{/* Additional Controls */}
|
||||||
<div className="flex gap-1">
|
<div className="flex gap-1">
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
@@ -477,6 +530,7 @@ export function EditorMenu({ editor }: EditorMenuProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rest of the components remain unchanged
|
||||||
function getActiveHeading(editor: Editor) {
|
function getActiveHeading(editor: Editor) {
|
||||||
if (editor.isActive("heading", { level: 1 })) return "1";
|
if (editor.isActive("heading", { level: 1 })) return "1";
|
||||||
if (editor.isActive("heading", { level: 2 })) return "2";
|
if (editor.isActive("heading", { level: 2 })) return "2";
|
||||||
222
frontend/components/editor/extensions/marks.ts
Normal file
222
frontend/components/editor/extensions/marks.ts
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
// extensions/customMarks.ts
|
||||||
|
import {
|
||||||
|
Mark,
|
||||||
|
markInputRule,
|
||||||
|
markPasteRule,
|
||||||
|
mergeAttributes,
|
||||||
|
} from "@tiptap/core";
|
||||||
|
|
||||||
|
// Define available size options
|
||||||
|
const sizeOptions = {
|
||||||
|
xs: "text-xs",
|
||||||
|
sm: "text-sm",
|
||||||
|
base: "text-base",
|
||||||
|
lg: "text-lg",
|
||||||
|
xl: "text-xl",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type SizeOption = keyof typeof sizeOptions;
|
||||||
|
|
||||||
|
export interface FontSizeOptions {
|
||||||
|
HTMLAttributes: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module "@tiptap/core" {
|
||||||
|
interface Commands<ReturnType> {
|
||||||
|
fontSize: {
|
||||||
|
setFontSize: (attributes: { size: SizeOption }) => ReturnType;
|
||||||
|
toggleFontSize: (attributes: { size: SizeOption }) => ReturnType;
|
||||||
|
unsetFontSize: () => ReturnType;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fontSizeInputRegex = /(?:^|\s)(~((?:[^~]+))~)$/;
|
||||||
|
export const fontSizePasteRegex = /(?:^|\s)(~((?:[^~]+))~)/g;
|
||||||
|
|
||||||
|
export const FontSize = Mark.create<FontSizeOptions>({
|
||||||
|
name: "fontSize",
|
||||||
|
|
||||||
|
addOptions() {
|
||||||
|
return {
|
||||||
|
HTMLAttributes: {},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
addAttributes() {
|
||||||
|
return {
|
||||||
|
size: {
|
||||||
|
default: "base",
|
||||||
|
parseHTML: (element: HTMLElement) => {
|
||||||
|
const sizeClass = Object.entries(sizeOptions).find(
|
||||||
|
([, className]) =>
|
||||||
|
element.classList.contains(className),
|
||||||
|
)?.[0];
|
||||||
|
return sizeClass || "base";
|
||||||
|
},
|
||||||
|
renderHTML: (attributes: { size: SizeOption }) => ({
|
||||||
|
class: sizeOptions[attributes.size],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
parseHTML() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
tag: "span",
|
||||||
|
getAttrs: (node: HTMLElement) => {
|
||||||
|
const hasSizeClass = Object.values(sizeOptions).some(
|
||||||
|
(className) => node.classList.contains(className),
|
||||||
|
);
|
||||||
|
return hasSizeClass ? {} : null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
renderHTML({ HTMLAttributes }) {
|
||||||
|
return [
|
||||||
|
"span",
|
||||||
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
||||||
|
0,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
addCommands() {
|
||||||
|
return {
|
||||||
|
setFontSize:
|
||||||
|
(attributes: { size: SizeOption }) =>
|
||||||
|
({ commands }) => {
|
||||||
|
return commands.setMark(this.name, attributes);
|
||||||
|
},
|
||||||
|
toggleFontSize:
|
||||||
|
(attributes: { size: SizeOption }) =>
|
||||||
|
({ commands }) => {
|
||||||
|
return commands.toggleMark(this.name, attributes);
|
||||||
|
},
|
||||||
|
unsetFontSize:
|
||||||
|
() =>
|
||||||
|
({ commands }) => {
|
||||||
|
return commands.unsetMark(this.name);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
"Mod-s": () => this.editor.commands.toggleFontSize({ size: "sm" }),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
addInputRules() {
|
||||||
|
return [
|
||||||
|
markInputRule({
|
||||||
|
find: fontSizeInputRegex,
|
||||||
|
type: this.type,
|
||||||
|
getAttributes: { size: "sm" }, // Default size for input rule
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
addPasteRules() {
|
||||||
|
return [
|
||||||
|
markPasteRule({
|
||||||
|
find: fontSizePasteRegex,
|
||||||
|
type: this.type,
|
||||||
|
getAttributes: { size: "sm" }, // Default size for paste rule
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// TextColor remains unchanged
|
||||||
|
export interface TextColorOptions {
|
||||||
|
HTMLAttributes: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module "@tiptap/core" {
|
||||||
|
interface Commands<ReturnType> {
|
||||||
|
textColor: {
|
||||||
|
setTextColor: (attributes: { color: string }) => ReturnType;
|
||||||
|
toggleTextColor: (attributes: { color: string }) => ReturnType;
|
||||||
|
unsetTextColor: () => ReturnType;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TextColor = Mark.create<TextColorOptions>({
|
||||||
|
name: "textColor",
|
||||||
|
addOptions() {
|
||||||
|
return {
|
||||||
|
HTMLAttributes: {},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
addAttributes() {
|
||||||
|
return {
|
||||||
|
color: {
|
||||||
|
default: null,
|
||||||
|
parseHTML: (element: HTMLElement) => {
|
||||||
|
const colorClass = Array.from(element.classList).find(
|
||||||
|
(cls) => cls.startsWith("text-"),
|
||||||
|
);
|
||||||
|
return colorClass ? colorClass.replace("text-", "") : null;
|
||||||
|
},
|
||||||
|
renderHTML: (attributes) => {
|
||||||
|
if (!attributes.color) return {};
|
||||||
|
// Use !important to override prose styles
|
||||||
|
return {
|
||||||
|
class: `text-${attributes.color} !text-${attributes.color}`,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
parseHTML() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
tag: "span",
|
||||||
|
getAttrs: (node: HTMLElement) => {
|
||||||
|
const colorClass = Array.from(node.classList).find((cls) =>
|
||||||
|
cls.startsWith("text-"),
|
||||||
|
);
|
||||||
|
return colorClass
|
||||||
|
? { color: colorClass.replace("text-", "") }
|
||||||
|
: null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
renderHTML({ HTMLAttributes }) {
|
||||||
|
return [
|
||||||
|
"span",
|
||||||
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
||||||
|
0,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
addCommands() {
|
||||||
|
return {
|
||||||
|
setTextColor:
|
||||||
|
(attributes: { color: string }) =>
|
||||||
|
({ commands }) => {
|
||||||
|
return commands.setMark(this.name, attributes);
|
||||||
|
},
|
||||||
|
toggleTextColor:
|
||||||
|
(attributes: { color: string }) =>
|
||||||
|
({ commands }) => {
|
||||||
|
return commands.toggleMark(this.name, attributes);
|
||||||
|
},
|
||||||
|
unsetTextColor:
|
||||||
|
() =>
|
||||||
|
({ commands }) => {
|
||||||
|
return commands.unsetMark(this.name);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
"Mod-Shift-c": () =>
|
||||||
|
this.editor.commands.toggleTextColor({ color: "gray-500" }),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -13,6 +13,7 @@ import TextAlign from "@tiptap/extension-text-align";
|
|||||||
import Youtube from "@tiptap/extension-youtube";
|
import Youtube from "@tiptap/extension-youtube";
|
||||||
import Dropcursor from "@tiptap/extension-dropcursor";
|
import Dropcursor from "@tiptap/extension-dropcursor";
|
||||||
import { EditorMenu } from "./editor-menu";
|
import { EditorMenu } from "./editor-menu";
|
||||||
|
import { FontSize, TextColor } from "./extensions/marks";
|
||||||
|
|
||||||
interface EditorProps {
|
interface EditorProps {
|
||||||
content: string;
|
content: string;
|
||||||
@@ -59,6 +60,8 @@ export function LocalEditor({
|
|||||||
const editor = useEditor({
|
const editor = useEditor({
|
||||||
extensions: [
|
extensions: [
|
||||||
StarterKit,
|
StarterKit,
|
||||||
|
FontSize,
|
||||||
|
TextColor,
|
||||||
Underline,
|
Underline,
|
||||||
Link,
|
Link,
|
||||||
Youtube,
|
Youtube,
|
||||||
@@ -30,25 +30,14 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import {
|
import { useForm } from "react-hook-form";
|
||||||
SubmitErrorHandler,
|
|
||||||
SubmitHandler,
|
|
||||||
useForm,
|
|
||||||
UseFormReturn,
|
|
||||||
} from "react-hook-form";
|
|
||||||
import { CalendarEventExternal } from "@schedule-x/calendar";
|
|
||||||
import ICalendarEvent from "@/interfaces/ICalendarEvent";
|
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export const eventFormSchema = z.object({
|
export const eventFormSchema = z.object({
|
||||||
title: z.string().min(1, "Titre requis"),
|
title: z.string().min(1, "Titre requis"),
|
||||||
startDate: z.date({
|
startDate: z.date({ required_error: "Date de début requise" }),
|
||||||
required_error: "Date de début requise",
|
|
||||||
}),
|
|
||||||
startTime: z.string(),
|
startTime: z.string(),
|
||||||
endDate: z.date({
|
endDate: z.date({ required_error: "Date finale requise" }),
|
||||||
required_error: "Date finale requise",
|
|
||||||
}),
|
|
||||||
endTime: z.string(),
|
endTime: z.string(),
|
||||||
fullDay: z.boolean().default(false),
|
fullDay: z.boolean().default(false),
|
||||||
frequency: z.enum(["unique", "quotidien", "hebdomadaire", "mensuel"]),
|
frequency: z.enum(["unique", "quotidien", "hebdomadaire", "mensuel"]),
|
||||||
@@ -65,37 +54,34 @@ const frequencies = [
|
|||||||
{ label: "Mensuel", value: "mensuel" },
|
{ label: "Mensuel", value: "mensuel" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const isCalendarEventExternal = (
|
|
||||||
event: CalendarEventExternal | Omit<CalendarEventExternal, "id">,
|
|
||||||
): event is CalendarEventExternal => {
|
|
||||||
return (event as CalendarEventExternal).id !== undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EventForm: React.FC<{
|
export const EventForm: React.FC<{
|
||||||
event: ICalendarEvent | Omit<ICalendarEvent, "id">;
|
event: any;
|
||||||
setForm: React.Dispatch<
|
setForm: React.Dispatch<
|
||||||
React.SetStateAction<UseFormReturn<EventFormValues> | undefined>
|
React.SetStateAction<
|
||||||
|
ReturnType<typeof useForm<EventFormValues>> | undefined
|
||||||
|
>
|
||||||
>;
|
>;
|
||||||
}> = ({ event, setForm }) => {
|
}> = ({ event, setForm }) => {
|
||||||
const _start = new Date(event.start ?? Date.now());
|
const _start = new Date(event.start ?? Date.now());
|
||||||
const _end = new Date(event.end ?? Date.now());
|
const _end = new Date(event.end ?? Date.now());
|
||||||
|
|
||||||
const form = useForm<EventFormValues>({
|
const form = useForm<EventFormValues>({
|
||||||
resolver: zodResolver(eventFormSchema),
|
resolver: zodResolver(eventFormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
title: event.title ? event.title : "",
|
title: event.title || "",
|
||||||
startDate: _start, // event.start),
|
startDate: _start,
|
||||||
startTime: format(_start, "HH:mm"),
|
startTime: format(_start, "HH:mm"),
|
||||||
endDate: _end, // event.end),
|
endDate: _end,
|
||||||
endTime: format(_end, "HH:mm"),
|
endTime: format(_end, "HH:mm"),
|
||||||
fullDay: event.fullday,
|
fullDay: event.fullday ?? false,
|
||||||
frequency: "unique",
|
frequency: "unique",
|
||||||
isVisible: event.isVisible,
|
isVisible: event.isVisible ?? true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setForm(form);
|
setForm(form);
|
||||||
}, []);
|
}, [form, setForm]);
|
||||||
|
|
||||||
const frequency = form.watch("frequency");
|
const frequency = form.watch("frequency");
|
||||||
|
|
||||||
@@ -120,53 +106,63 @@ export const EventForm: React.FC<{
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="grid grid-cols-[1fr,auto,1fr] items-end gap-2">
|
<div className="grid grid-cols-[1fr,auto,1fr] items-end gap-2">
|
||||||
<FormField
|
{/* Simplified startDate without FormField */}
|
||||||
control={form.control}
|
|
||||||
name="startDate"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex flex-col">
|
<FormItem className="flex flex-col">
|
||||||
<FormLabel>Début</FormLabel>
|
<FormLabel>Début</FormLabel>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<FormControl>
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full pl-3 text-left font-normal",
|
"w-full pl-3 text-left font-normal",
|
||||||
!field.value &&
|
!form.getValues("startDate") &&
|
||||||
"text-muted-foreground",
|
"text-muted-foreground",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{field.value ? (
|
{form.getValues("startDate") ? (
|
||||||
format(
|
format(
|
||||||
field.value,
|
form.getValues("startDate"),
|
||||||
"dd/MM/yyyy",
|
"dd/MM/yyyy",
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<span>
|
<span>Choisis une date</span>
|
||||||
Choisis une date
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
||||||
</Button>
|
</Button>
|
||||||
</FormControl>
|
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent
|
<PopoverContent
|
||||||
className="w-auto p-0"
|
className="w-auto p-0"
|
||||||
align="start"
|
align="start"
|
||||||
>
|
>
|
||||||
|
<div style={{ pointerEvents: "auto" }}>
|
||||||
|
{/* Force interactivity */}
|
||||||
<Calendar
|
<Calendar
|
||||||
mode="single"
|
mode="single"
|
||||||
selected={field.value}
|
selected={form.getValues("startDate")}
|
||||||
onSelect={field.onChange}
|
onSelect={(date) => {
|
||||||
|
console.log(
|
||||||
|
"Start date selected:",
|
||||||
|
date,
|
||||||
|
);
|
||||||
|
if (date) {
|
||||||
|
form.setValue(
|
||||||
|
"startDate",
|
||||||
|
date,
|
||||||
|
{ shouldValidate: true },
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"Updated startDate:",
|
||||||
|
form.getValues("startDate"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
initialFocus
|
initialFocus
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
@@ -187,53 +183,60 @@ export const EventForm: React.FC<{
|
|||||||
|
|
||||||
<span className="invisible">Until</span>
|
<span className="invisible">Until</span>
|
||||||
|
|
||||||
<FormField
|
{/* Simplified endDate */}
|
||||||
control={form.control}
|
|
||||||
name="endDate"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex flex-col">
|
<FormItem className="flex flex-col">
|
||||||
<FormLabel>Fin</FormLabel>
|
<FormLabel>Fin</FormLabel>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<FormControl>
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full pl-3 text-left font-normal",
|
"w-full pl-3 text-left font-normal",
|
||||||
!field.value &&
|
!form.getValues("endDate") &&
|
||||||
"text-muted-foreground",
|
"text-muted-foreground",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{field.value ? (
|
{form.getValues("endDate") ? (
|
||||||
format(
|
format(
|
||||||
field.value,
|
form.getValues("endDate"),
|
||||||
"dd/MM/yyyy",
|
"dd/MM/yyyy",
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<span>
|
<span>Choisis une date</span>
|
||||||
Choisis une date
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
||||||
</Button>
|
</Button>
|
||||||
</FormControl>
|
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent
|
<PopoverContent
|
||||||
className="w-auto p-0"
|
className="w-auto p-0"
|
||||||
align="start"
|
align="start"
|
||||||
>
|
>
|
||||||
|
<div style={{ pointerEvents: "auto" }}>
|
||||||
<Calendar
|
<Calendar
|
||||||
mode="single"
|
mode="single"
|
||||||
selected={field.value}
|
selected={form.getValues("endDate")}
|
||||||
onSelect={field.onChange}
|
onSelect={(date) => {
|
||||||
|
console.log(
|
||||||
|
"End date selected:",
|
||||||
|
date,
|
||||||
|
);
|
||||||
|
if (date) {
|
||||||
|
form.setValue("endDate", date, {
|
||||||
|
shouldValidate: true,
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
"Updated endDate:",
|
||||||
|
form.getValues("endDate"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
initialFocus
|
initialFocus
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
@@ -303,54 +306,72 @@ export const EventForm: React.FC<{
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{frequency !== "unique" && (
|
{frequency !== "unique" && (
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="frequencyEndDate"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
<FormItem className="flex-1">
|
||||||
<FormLabel>Jusqu'au</FormLabel>
|
<FormLabel>Jusqu'au</FormLabel>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<FormControl>
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full pl-3 text-left font-normal",
|
"w-full pl-3 text-left font-normal",
|
||||||
!field.value &&
|
!form.getValues(
|
||||||
"text-muted-foreground",
|
"frequencyEndDate",
|
||||||
|
) && "text-muted-foreground",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{field.value ? (
|
{form.getValues("frequencyEndDate") ? (
|
||||||
format(
|
format(
|
||||||
field.value,
|
form.getValues(
|
||||||
|
"frequencyEndDate",
|
||||||
|
)!,
|
||||||
"dd/MM/yyyy",
|
"dd/MM/yyyy",
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<span>
|
<span>Choisis une date</span>
|
||||||
Choisis une date
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
||||||
</Button>
|
</Button>
|
||||||
</FormControl>
|
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent
|
<PopoverContent
|
||||||
className="w-auto p-0"
|
className="w-auto p-0"
|
||||||
align="start"
|
align="start"
|
||||||
>
|
>
|
||||||
|
<div style={{ pointerEvents: "auto" }}>
|
||||||
<Calendar
|
<Calendar
|
||||||
mode="single"
|
mode="single"
|
||||||
selected={field.value}
|
selected={form.getValues(
|
||||||
onSelect={field.onChange}
|
"frequencyEndDate",
|
||||||
|
)}
|
||||||
|
onSelect={(date) => {
|
||||||
|
console.log(
|
||||||
|
"Frequency end date selected:",
|
||||||
|
date,
|
||||||
|
);
|
||||||
|
if (date) {
|
||||||
|
form.setValue(
|
||||||
|
"frequencyEndDate",
|
||||||
|
date,
|
||||||
|
{
|
||||||
|
shouldValidate:
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"Updated frequencyEndDate:",
|
||||||
|
form.getValues(
|
||||||
|
"frequencyEndDate",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
initialFocus
|
initialFocus
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
|
|||||||
@@ -1,38 +1,17 @@
|
|||||||
import { SITE_NAME } from "@/lib/constants";
|
import { SITE_NAME } from "@/lib/constants";
|
||||||
import {
|
import { FaFacebook, FaYoutube } from "react-icons/fa";
|
||||||
FaFacebook,
|
import Logo from "./logo";
|
||||||
FaInstagram,
|
|
||||||
FaLinkedin,
|
|
||||||
FaTwitter,
|
|
||||||
FaYoutube,
|
|
||||||
} from "react-icons/fa";
|
|
||||||
|
|
||||||
const sections = [
|
const sections = [
|
||||||
{
|
|
||||||
title: "Product",
|
|
||||||
links: [
|
|
||||||
{ name: "Overview", href: "#" },
|
|
||||||
{ name: "Pricing", href: "#" },
|
|
||||||
{ name: "Marketplace", href: "#" },
|
|
||||||
{ name: "Features", href: "#" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Company",
|
|
||||||
links: [
|
|
||||||
{ name: "About", href: "#" },
|
|
||||||
{ name: "Team", href: "#" },
|
|
||||||
{ name: "Blog", href: "#" },
|
|
||||||
{ name: "Careers", href: "#" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: "Resources",
|
title: "Resources",
|
||||||
links: [
|
links: [
|
||||||
{ name: "Help", href: "#" },
|
{ name: "Accueil", href: "/" },
|
||||||
{ name: "Sales", href: "#" },
|
{ name: "Planning", href: "/planning" },
|
||||||
{ name: "Advertise", href: "#" },
|
{ name: "À propos", href: "/about" },
|
||||||
{ name: "Privacy", href: "#" },
|
{ name: "Galerie", href: "/gallery" },
|
||||||
|
{ name: "Blog", href: "/blogs" },
|
||||||
|
{ name: "Contact", href: "/contact" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -46,20 +25,12 @@ const Footer = () => {
|
|||||||
<div className="flex w-full max-w-96 shrink flex-col items-center justify-between gap-6 lg:items-start">
|
<div className="flex w-full max-w-96 shrink flex-col items-center justify-between gap-6 lg:items-start">
|
||||||
<div>
|
<div>
|
||||||
<span className="flex items-center justify-center gap-4 lg:justify-start">
|
<span className="flex items-center justify-center gap-4 lg:justify-start">
|
||||||
<img
|
<Logo className="h-11 w-11" />
|
||||||
src="https://shadcnblocks.com/images/block/block-1.svg"
|
|
||||||
alt="logo"
|
|
||||||
className="h-11"
|
|
||||||
/>
|
|
||||||
<p className="text-3xl font-semibold">
|
<p className="text-3xl font-semibold">
|
||||||
{SITE_NAME}
|
{SITE_NAME}
|
||||||
</p>
|
</p>
|
||||||
</span>
|
</span>
|
||||||
<p className="mt-6 text-sm text-muted-foreground">
|
<p className="mt-6 text-sm text-muted-foreground"></p>
|
||||||
A collection of 100+ responsive HTML
|
|
||||||
templates for your startup business or side
|
|
||||||
project.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<ul className="flex items-center space-x-6 text-muted-foreground">
|
<ul className="flex items-center space-x-6 text-muted-foreground">
|
||||||
<li className="font-medium hover:text-primary">
|
<li className="font-medium hover:text-primary">
|
||||||
@@ -74,7 +45,9 @@ const Footer = () => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-3 gap-6 lg:gap-20">
|
<div
|
||||||
|
className={`grid grid-cols-[${sections.length}] gap-6 lg:gap-20`}
|
||||||
|
>
|
||||||
{sections.map((section, sectionIdx) => (
|
{sections.map((section, sectionIdx) => (
|
||||||
<div key={sectionIdx}>
|
<div key={sectionIdx}>
|
||||||
<h3 className="mb-6 font-bold">
|
<h3 className="mb-6 font-bold">
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useRouter, useSearchParams } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import useLogin from "@/hooks/use-login";
|
import useLogin from "@/hooks/use-login";
|
||||||
import { Loader2 } from "lucide-react";
|
import {
|
||||||
|
ActionButton,
|
||||||
|
ActionButtonDefault,
|
||||||
|
ActionButtonError,
|
||||||
|
ActionButtonLoading,
|
||||||
|
ActionButtonSuccess,
|
||||||
|
} from "./action-button";
|
||||||
|
|
||||||
export function LoginForm({
|
export function LoginForm({
|
||||||
className,
|
className,
|
||||||
@@ -70,7 +75,7 @@ export function LoginForm({
|
|||||||
href="#"
|
href="#"
|
||||||
className="ml-auto text-sm underline-offset-4 hover:underline"
|
className="ml-auto text-sm underline-offset-4 hover:underline"
|
||||||
>
|
>
|
||||||
Forgot your password?
|
Mot de passe oublier
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
@@ -82,35 +87,23 @@ export function LoginForm({
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<ActionButton
|
||||||
disabled={loading}
|
isLoading={loading}
|
||||||
|
isSuccess={isSuccess}
|
||||||
type="submit"
|
type="submit"
|
||||||
className="w-full transition-all ease-in-out"
|
|
||||||
>
|
>
|
||||||
{loading && <Loader2 className="animate-spin" />}
|
<ActionButtonDefault>Se connecter</ActionButtonDefault>
|
||||||
Se connecter
|
<ActionButtonLoading />
|
||||||
</Button>
|
<ActionButtonError />
|
||||||
<div className="relative text-center text-sm after:absolute after:inset-0 after:top-1/2 after:z-0 after:flex after:items-center after:border-t after:border-border">
|
<ActionButtonSuccess />
|
||||||
<span className="relative z-10 bg-background px-2 text-muted-foreground">
|
</ActionButton>
|
||||||
Ou connectez-vous avec
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<Button variant="outline" className="w-full">
|
{/*<div className="text-center text-sm">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
||||||
<path
|
|
||||||
d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"
|
|
||||||
fill="currentColor"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
Login with GitHub
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div className="text-center text-sm">
|
|
||||||
Pas de compte ?{" "}
|
Pas de compte ?{" "}
|
||||||
<a href="#" className="underline underline-offset-4">
|
<a href="#" className="underline underline-offset-4">
|
||||||
Créer un compte
|
Créer un compte
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>*/}
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import * as z from "zod";
|
import * as z from "zod";
|
||||||
@@ -28,6 +28,16 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "./ui/select";
|
} from "./ui/select";
|
||||||
|
import { useApi } from "@/hooks/use-api";
|
||||||
|
import { Role, User } from "@/types/types";
|
||||||
|
import { Badge } from "./ui/badge";
|
||||||
|
import { Building, X } from "lucide-react";
|
||||||
|
|
||||||
|
// Define the Role schema based on assumed Role type
|
||||||
|
const roleSchema = z.object({
|
||||||
|
id: z.string().min(1, "Role ID is required"),
|
||||||
|
name: z.string().min(1, "Role name is required"),
|
||||||
|
});
|
||||||
|
|
||||||
const memberSchema = z.object({
|
const memberSchema = z.object({
|
||||||
userId: z.string().optional(),
|
userId: z.string().optional(),
|
||||||
@@ -39,7 +49,10 @@ const memberSchema = z.object({
|
|||||||
.min(6, "Le mot de passe doit avoir au moins 6 caractères.")
|
.min(6, "Le mot de passe doit avoir au moins 6 caractères.")
|
||||||
.optional(),
|
.optional(),
|
||||||
phone: z.string().regex(/^\d{10}$/, "Le numéro doit avoir 10 chiffres."),
|
phone: z.string().regex(/^\d{10}$/, "Le numéro doit avoir 10 chiffres."),
|
||||||
role: z.string().min(1, "Le rôle est requis."),
|
roles: z
|
||||||
|
.array(roleSchema)
|
||||||
|
.min(1, "At least one role is required")
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateMemberSchema = memberSchema.partial();
|
const updateMemberSchema = memberSchema.partial();
|
||||||
@@ -60,6 +73,8 @@ export default function MemberDialog({
|
|||||||
onSave,
|
onSave,
|
||||||
}: MemberDialogProps) {
|
}: MemberDialogProps) {
|
||||||
const schema = member?.userId ? updateMemberSchema : memberSchema;
|
const schema = member?.userId ? updateMemberSchema : memberSchema;
|
||||||
|
const { data: availableRoles = [] } = useApi<Role[]>("/roles", {}, true); // Fetch roles
|
||||||
|
|
||||||
const form = useForm<Member>({
|
const form = useForm<Member>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: member?.userId
|
defaultValues: member?.userId
|
||||||
@@ -71,7 +86,7 @@ export default function MemberDialog({
|
|||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
phone: "",
|
phone: "",
|
||||||
role: "",
|
roles: [], // Default to empty array
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -86,11 +101,38 @@ export default function MemberDialog({
|
|||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
phone: "",
|
phone: "",
|
||||||
role: "",
|
roles: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [member, form]);
|
}, [member, form]);
|
||||||
|
|
||||||
|
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
||||||
|
|
||||||
|
const addRole = () => {
|
||||||
|
if (selectedRole) {
|
||||||
|
const currentRoles = form.getValues("roles");
|
||||||
|
if (!currentRoles?.some((role) => role.id === selectedRole.id)) {
|
||||||
|
form.setValue(
|
||||||
|
"roles",
|
||||||
|
[...(currentRoles || []), selectedRole],
|
||||||
|
{
|
||||||
|
shouldValidate: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
setSelectedRole(null); // Reset selection
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeRole = (roleToRemove: Role) => {
|
||||||
|
const currentRoles = form.getValues("roles");
|
||||||
|
form.setValue(
|
||||||
|
"roles",
|
||||||
|
currentRoles?.filter((role) => role.id !== roleToRemove.id),
|
||||||
|
{ shouldValidate: true },
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = (data: Member) => {
|
const onSubmit = (data: Member) => {
|
||||||
onSave(data);
|
onSave(data);
|
||||||
onClose();
|
onClose();
|
||||||
@@ -118,13 +160,13 @@ export default function MemberDialog({
|
|||||||
name="firstname"
|
name="firstname"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="grid gap-2">
|
<FormItem className="grid gap-2">
|
||||||
<FormLabel htmlFor="name">
|
<FormLabel htmlFor="firstname">
|
||||||
Prénom
|
Prénom
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
id="firstname"
|
id="firstname"
|
||||||
placeholder="John Doe"
|
placeholder="John"
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="firstname"
|
autoComplete="firstname"
|
||||||
{...field}
|
{...field}
|
||||||
@@ -134,8 +176,8 @@ export default function MemberDialog({
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="grid gap-4">
|
|
||||||
{/* Firstname Field */}
|
{/* Lastname Field */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="lastname"
|
name="lastname"
|
||||||
@@ -147,7 +189,7 @@ export default function MemberDialog({
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
id="lastname"
|
id="lastname"
|
||||||
placeholder="John Doe"
|
placeholder="Doe"
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="lastname"
|
autoComplete="lastname"
|
||||||
{...field}
|
{...field}
|
||||||
@@ -180,7 +222,8 @@ export default function MemberDialog({
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{/* Password Field */}
|
|
||||||
|
{/* Password Field (only for new members) */}
|
||||||
{!member?.userId && (
|
{!member?.userId && (
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
@@ -205,44 +248,6 @@ export default function MemberDialog({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="role"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="grid gap-2">
|
|
||||||
<FormLabel htmlFor="role">
|
|
||||||
Role
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Select
|
|
||||||
value={field.value}
|
|
||||||
onValueChange={(
|
|
||||||
value: string,
|
|
||||||
) => field.onChange(value)}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-[180px]">
|
|
||||||
<SelectValue placeholder="Séléctionner un rôle" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectGroup>
|
|
||||||
<SelectLabel>
|
|
||||||
Role
|
|
||||||
</SelectLabel>
|
|
||||||
<SelectItem value="admin">
|
|
||||||
Administrateur
|
|
||||||
</SelectItem>
|
|
||||||
<SelectItem value="user">
|
|
||||||
Utilisateur
|
|
||||||
</SelectItem>
|
|
||||||
</SelectGroup>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Phone Field */}
|
{/* Phone Field */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
@@ -265,7 +270,97 @@ export default function MemberDialog({
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Roles Field */}
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="roles"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="grid gap-2">
|
||||||
|
<FormLabel>Roles</FormLabel>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{field.value?.map((role) => (
|
||||||
|
<Badge
|
||||||
|
key={role.id}
|
||||||
|
variant="secondary"
|
||||||
|
className="text-sm py-1 px-2"
|
||||||
|
>
|
||||||
|
{role.name}
|
||||||
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
removeRole(role)
|
||||||
|
}
|
||||||
|
className="ml-2 text-gray-500 hover:text-gray-700"
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3" />
|
||||||
|
</button>
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex space-x-2 mt-2">
|
||||||
|
<Select
|
||||||
|
value={
|
||||||
|
selectedRole
|
||||||
|
? selectedRole.name
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
const role =
|
||||||
|
availableRoles.find(
|
||||||
|
(r) =>
|
||||||
|
r.name ===
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
if (role)
|
||||||
|
setSelectedRole(role);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Sélectionner un rôle" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
<SelectLabel>
|
||||||
|
Roles
|
||||||
|
</SelectLabel>
|
||||||
|
{availableRoles
|
||||||
|
.filter(
|
||||||
|
(role) =>
|
||||||
|
!field.value?.some(
|
||||||
|
(r) =>
|
||||||
|
r.id ===
|
||||||
|
role.id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.map((role) => (
|
||||||
|
<SelectItem
|
||||||
|
key={
|
||||||
|
role.id
|
||||||
|
}
|
||||||
|
value={
|
||||||
|
role.name
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{role.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
disabled={!selectedRole}
|
||||||
|
onClick={addRole}
|
||||||
|
className="flex items-center"
|
||||||
|
>
|
||||||
|
<Building className="mr-2 h-4 w-4" />
|
||||||
|
Ajouter le rôle
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button type="submit">
|
<Button type="submit">
|
||||||
|
|||||||
@@ -10,21 +10,19 @@ import {
|
|||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
import MemberDialog, { Member } from "./member-dialog";
|
import MemberDialog, { Member } from "./member-dialog";
|
||||||
import { useApi } from "@/hooks/use-api";
|
import { useApi } from "@/hooks/use-api";
|
||||||
import request from "@/lib/request";
|
import request from "@/lib/request";
|
||||||
import {
|
import { Loader2, MoreHorizontal, UserRoundPlus } from "lucide-react";
|
||||||
CircleX,
|
|
||||||
Loader2,
|
|
||||||
Trash2,
|
|
||||||
UserRoundPen,
|
|
||||||
UserRoundPlus,
|
|
||||||
} from "lucide-react";
|
|
||||||
import Link from "next/link";
|
|
||||||
import IUser from "@/interfaces/IUser";
|
import IUser from "@/interfaces/IUser";
|
||||||
import hasPermissions from "@/lib/hasPermissions";
|
import hasPermissions from "@/lib/hasPermissions";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "./ui/dropdown-menu";
|
||||||
|
|
||||||
export default function MembersTable({ user }: { user: IUser }) {
|
export default function MembersTable({ user }: { user: IUser }) {
|
||||||
const {
|
const {
|
||||||
@@ -34,23 +32,12 @@ export default function MembersTable({ user }: { user: IUser }) {
|
|||||||
success,
|
success,
|
||||||
isLoading,
|
isLoading,
|
||||||
} = useApi<Member[]>("/users", undefined, true, false);
|
} = useApi<Member[]>("/users", undefined, true, false);
|
||||||
const [selectMode, setSelectMode] = useState(false);
|
|
||||||
const [selectedMembers, setSelectedMembers] = useState<string[]>([]);
|
|
||||||
const [dialogOpen, setDialogOpen] = useState(false);
|
const [dialogOpen, setDialogOpen] = useState(false);
|
||||||
const [currentMember, setCurrentMember] = useState<Member | null>(null);
|
const [currentMember, setCurrentMember] = useState<Member | null>(null);
|
||||||
|
|
||||||
const toggleSelectMode = () => {
|
const { users } = hasPermissions(user.roles, {
|
||||||
setSelectMode(!selectMode);
|
users: ["delete", "update", "insert"],
|
||||||
setSelectedMembers([]);
|
} as const);
|
||||||
};
|
|
||||||
|
|
||||||
const toggleMemberSelection = (userId: string) => {
|
|
||||||
setSelectedMembers((prev) =>
|
|
||||||
prev.includes(userId)
|
|
||||||
? prev.filter((id) => id !== userId)
|
|
||||||
: [...prev, userId],
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOpenDialog = (member: Member | null) => {
|
const handleOpenDialog = (member: Member | null) => {
|
||||||
setCurrentMember(member);
|
setCurrentMember(member);
|
||||||
@@ -59,10 +46,12 @@ export default function MembersTable({ user }: { user: IUser }) {
|
|||||||
|
|
||||||
const handleSaveMember = async (savedMember: Member) => {
|
const handleSaveMember = async (savedMember: Member) => {
|
||||||
if (savedMember.userId) {
|
if (savedMember.userId) {
|
||||||
|
const dif = DiffUtils.getDifferences(currentMember!, savedMember);
|
||||||
|
if (DiffUtils.isEmpty(dif)) return;
|
||||||
const res = await request<unknown>(
|
const res = await request<unknown>(
|
||||||
`/users/${savedMember.userId}/update`,
|
`/users/${savedMember.userId}/update`,
|
||||||
{
|
{
|
||||||
body: savedMember,
|
body: dif,
|
||||||
requiresAuth: true,
|
requiresAuth: true,
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
},
|
},
|
||||||
@@ -96,105 +85,83 @@ export default function MembersTable({ user }: { user: IUser }) {
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<Button onClick={toggleSelectMode}>
|
{users.insert && (
|
||||||
{selectMode ? <CircleX /> : "Selectionner"}
|
|
||||||
</Button>
|
|
||||||
{hasPermissions(user.roles, { users: ["insert"] }) && (
|
|
||||||
<Button onClick={() => handleOpenDialog(null)}>
|
<Button onClick={() => handleOpenDialog(null)}>
|
||||||
<UserRoundPlus />
|
<UserRoundPlus />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
{isLoading && <Loader2 className="animate-spin" />}
|
||||||
<ScrollArea className="h-full rounded-md border">
|
<ScrollArea className="h-full rounded-md border">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader className="sticky top-0 bg-background z-10 shadow-sm">
|
<TableHeader className="sticky top-0 bg-background z-10 shadow-sm">
|
||||||
<TableRow>
|
<TableRow>
|
||||||
{selectMode && (
|
|
||||||
<TableHead className="w-[50px]">
|
|
||||||
Sélectionner
|
|
||||||
</TableHead>
|
|
||||||
)}
|
|
||||||
<TableHead>Prénom</TableHead>
|
<TableHead>Prénom</TableHead>
|
||||||
<TableHead>Nom</TableHead>
|
<TableHead>Nom</TableHead>
|
||||||
<TableHead>Email</TableHead>
|
<TableHead>Email</TableHead>
|
||||||
<TableHead>Téléphone</TableHead>
|
<TableHead>Téléphone</TableHead>
|
||||||
<TableHead>Rôle</TableHead>
|
<TableHead>Rôles</TableHead>
|
||||||
<TableHead className="text-right">
|
<TableHead className="text-right">
|
||||||
Actions
|
Actions
|
||||||
</TableHead>
|
</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{isLoading && <Loader2 className="animate-spin" />}
|
|
||||||
{members &&
|
{members &&
|
||||||
members.map((member) => (
|
members.map((_member) => (
|
||||||
<TableRow key={member.userId}>
|
<TableRow key={_member.userId}>
|
||||||
{selectMode && (
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Checkbox
|
{_member.firstname}
|
||||||
checked={selectedMembers.includes(
|
</TableCell>
|
||||||
member.userId!,
|
<TableCell>
|
||||||
)}
|
{_member.lastname}
|
||||||
onCheckedChange={() =>
|
</TableCell>
|
||||||
toggleMemberSelection(
|
<TableCell>{_member.email}</TableCell>
|
||||||
member.userId!,
|
<TableCell>{_member.phone}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{_member.roles
|
||||||
|
?.map((r) => r.name)
|
||||||
|
.join(", ")}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<span className="sr-only">
|
||||||
|
Ouvrir le menu
|
||||||
|
</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
{users.update && (
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() =>
|
||||||
|
handleOpenDialog(
|
||||||
|
_member,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
>
|
||||||
</TableCell>
|
Mettre à jour
|
||||||
|
</DropdownMenuItem>
|
||||||
)}
|
)}
|
||||||
<TableCell>
|
{users.delete && (
|
||||||
<Link
|
<DropdownMenuItem
|
||||||
href={`/dashboard/members/${member.userId}`}
|
|
||||||
>
|
|
||||||
<span className="underline">
|
|
||||||
{member.firstname}
|
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<Link
|
|
||||||
href={`/dashboard/members/${member.userId}`}
|
|
||||||
>
|
|
||||||
<span className="underline">
|
|
||||||
{member.lastname}
|
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>{member.email}</TableCell>
|
|
||||||
<TableCell>{member.phone}</TableCell>
|
|
||||||
<TableCell>{member.role}</TableCell>
|
|
||||||
<TableCell className="text-right">
|
|
||||||
{hasPermissions(user.roles, {
|
|
||||||
users: ["update"],
|
|
||||||
}) && (
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="mr-2"
|
|
||||||
onClick={() =>
|
|
||||||
handleOpenDialog(member)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<UserRoundPen />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{hasPermissions(user.roles, {
|
|
||||||
users: ["delete"],
|
|
||||||
}) && (
|
|
||||||
<Button
|
|
||||||
variant="destructive"
|
|
||||||
size="sm"
|
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
handleDelete(
|
handleDelete(
|
||||||
member.userId!,
|
_member.userId!,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Trash2 />
|
Supprimer
|
||||||
</Button>
|
</DropdownMenuItem>
|
||||||
)}
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ import ShortcodeDialog from "@/components/shortcode-dialogue";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import IUser from "@/interfaces/IUser";
|
import IUser from "@/interfaces/IUser";
|
||||||
import hasPermissions from "@/lib/hasPermissions";
|
import hasPermissions from "@/lib/hasPermissions";
|
||||||
|
import {
|
||||||
|
HoverCard,
|
||||||
|
HoverCardContent,
|
||||||
|
HoverCardTrigger,
|
||||||
|
} from "@radix-ui/react-hover-card";
|
||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
interface ShortcodeTableProps {
|
interface ShortcodeTableProps {
|
||||||
user: IUser;
|
user: IUser;
|
||||||
@@ -37,13 +43,17 @@ export function ShortcodeTable({
|
|||||||
onAdd,
|
onAdd,
|
||||||
user,
|
user,
|
||||||
}: ShortcodeTableProps) {
|
}: ShortcodeTableProps) {
|
||||||
|
const permissions = hasPermissions(user.roles, {
|
||||||
|
shortcodes: ["insert", "update", "delete"],
|
||||||
|
} as const);
|
||||||
const [shortcodeSelected, setUpdateDialog] = useState<IShortcode | null>(
|
const [shortcodeSelected, setUpdateDialog] = useState<IShortcode | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
const [addDialog, setAddDialog] = useState<boolean>(false);
|
const [addDialog, setAddDialog] = useState<boolean>(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{hasPermissions(user.roles, { shortcodes: ["insert"] }) && (
|
{permissions.shortcodes.insert && (
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -81,7 +91,21 @@ export function ShortcodeTable({
|
|||||||
{shortcode.value || "N/A"}
|
{shortcode.value || "N/A"}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
|
<HoverCard>
|
||||||
|
<HoverCardTrigger className="underline decoration-dotted cursor-pointer">
|
||||||
{shortcode.media_id || "N/A"}
|
{shortcode.media_id || "N/A"}
|
||||||
|
</HoverCardTrigger>
|
||||||
|
{shortcode.media && (
|
||||||
|
<HoverCardContent>
|
||||||
|
<Image
|
||||||
|
src={shortcode.media.url}
|
||||||
|
alt={shortcode.media.alt}
|
||||||
|
width={200}
|
||||||
|
height={200}
|
||||||
|
/>
|
||||||
|
</HoverCardContent>
|
||||||
|
)}
|
||||||
|
</HoverCard>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
@@ -97,9 +121,7 @@ export function ShortcodeTable({
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{hasPermissions(user.roles, {
|
{permissions.shortcodes.update && (
|
||||||
shortcodes: ["update"],
|
|
||||||
}) && (
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setUpdateDialog(
|
setUpdateDialog(
|
||||||
@@ -110,9 +132,7 @@ export function ShortcodeTable({
|
|||||||
Mettre à jour
|
Mettre à jour
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
)}
|
)}
|
||||||
{hasPermissions(user.roles, {
|
{permissions.shortcodes.delete && (
|
||||||
shortcodes: ["delete"],
|
|
||||||
}) && (
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onDelete(shortcode.code)
|
onDelete(shortcode.code)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { ChevronLeft, ChevronRight } from "lucide-react"
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||||
import { DayPicker } from "react-day-picker"
|
import { DayPicker } from "react-day-picker";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
import { buttonVariants } from "@/components/ui/button"
|
import { buttonVariants } from "@/components/ui/button";
|
||||||
|
|
||||||
export type CalendarProps = React.ComponentProps<typeof DayPicker>
|
export type CalendarProps = React.ComponentProps<typeof DayPicker>;
|
||||||
|
|
||||||
function Calendar({
|
function Calendar({
|
||||||
className,
|
className,
|
||||||
@@ -27,7 +27,7 @@ function Calendar({
|
|||||||
nav: "space-x-1 flex items-center",
|
nav: "space-x-1 flex items-center",
|
||||||
nav_button: cn(
|
nav_button: cn(
|
||||||
buttonVariants({ variant: "outline" }),
|
buttonVariants({ variant: "outline" }),
|
||||||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
|
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100",
|
||||||
),
|
),
|
||||||
nav_button_previous: "absolute left-1",
|
nav_button_previous: "absolute left-1",
|
||||||
nav_button_next: "absolute right-1",
|
nav_button_next: "absolute right-1",
|
||||||
@@ -40,11 +40,11 @@ function Calendar({
|
|||||||
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",
|
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",
|
||||||
props.mode === "range"
|
props.mode === "range"
|
||||||
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
|
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
|
||||||
: "[&:has([aria-selected])]:rounded-md"
|
: "[&:has([aria-selected])]:rounded-md",
|
||||||
),
|
),
|
||||||
day: cn(
|
day: cn(
|
||||||
buttonVariants({ variant: "ghost" }),
|
buttonVariants({ variant: "ghost" }),
|
||||||
"h-8 w-8 p-0 font-normal aria-selected:opacity-100"
|
"h-8 w-8 p-0 font-normal aria-selected:opacity-100",
|
||||||
),
|
),
|
||||||
day_range_start: "day-range-start",
|
day_range_start: "day-range-start",
|
||||||
day_range_end: "day-range-end",
|
day_range_end: "day-range-end",
|
||||||
@@ -61,16 +61,22 @@ function Calendar({
|
|||||||
}}
|
}}
|
||||||
components={{
|
components={{
|
||||||
IconLeft: ({ className, ...props }) => (
|
IconLeft: ({ className, ...props }) => (
|
||||||
<ChevronLeft className={cn("h-4 w-4", className)} {...props} />
|
<ChevronLeft
|
||||||
|
className={cn("h-4 w-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
IconRight: ({ className, ...props }) => (
|
IconRight: ({ className, ...props }) => (
|
||||||
<ChevronRight className={cn("h-4 w-4", className)} {...props} />
|
<ChevronRight
|
||||||
|
className={cn("h-4 w-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
Calendar.displayName = "Calendar"
|
Calendar.displayName = "Calendar";
|
||||||
|
|
||||||
export { Calendar }
|
export { Calendar };
|
||||||
|
|||||||
29
frontend/components/ui/hover-card.tsx
Normal file
29
frontend/components/ui/hover-card.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const HoverCard = HoverCardPrimitive.Root;
|
||||||
|
|
||||||
|
const HoverCardTrigger = HoverCardPrimitive.Trigger;
|
||||||
|
|
||||||
|
const HoverCardContent = React.forwardRef<
|
||||||
|
React.ComponentRef<typeof HoverCardPrimitive.Content>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
|
||||||
|
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
||||||
|
<HoverCardPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
align={align}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none 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-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
|
||||||
|
|
||||||
|
export { HoverCard, HoverCardTrigger, HoverCardContent };
|
||||||
@@ -24,7 +24,7 @@ const ScrollArea = React.forwardRef<
|
|||||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
|
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
|
||||||
|
|
||||||
const ScrollBar = React.forwardRef<
|
const ScrollBar = React.forwardRef<
|
||||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
React.ComponentRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||||
React.ComponentPropsWithoutRef<
|
React.ComponentPropsWithoutRef<
|
||||||
typeof ScrollAreaPrimitive.ScrollAreaScrollbar
|
typeof ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ const toastVariants = cva(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const Toast = React.forwardRef<
|
const Toast = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
React.ComponentRef<typeof ToastPrimitives.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||||
VariantProps<typeof toastVariants>
|
VariantProps<typeof toastVariants>
|
||||||
>(({ className, variant, ...props }, ref) => {
|
>(({ className, variant, ...props }, ref) => {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const ToggleGroupContext = React.createContext<
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ToggleGroup = React.forwardRef<
|
const ToggleGroup = React.forwardRef<
|
||||||
React.ElementRef<typeof ToggleGroupPrimitive.Root>,
|
React.ComponentRef<typeof ToggleGroupPrimitive.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
|
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
|
||||||
VariantProps<typeof toggleVariants>
|
VariantProps<typeof toggleVariants>
|
||||||
>(({ className, variant, size, children, ...props }, ref) => (
|
>(({ className, variant, size, children, ...props }, ref) => (
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const toggleVariants = cva(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const Toggle = React.forwardRef<
|
const Toggle = React.forwardRef<
|
||||||
React.ElementRef<typeof TogglePrimitive.Root>,
|
React.ComponentRef<typeof TogglePrimitive.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
|
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
|
||||||
VariantProps<typeof toggleVariants>
|
VariantProps<typeof toggleVariants>
|
||||||
>(({ className, variant, size, ...props }, ref) => (
|
>(({ className, variant, size, ...props }, ref) => (
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
export const API_URL = process.env.NEXT_PUBLIC_API_URL ?? "";
|
export const API_URL = process.env.NEXT_PUBLIC_API_URL ?? "";
|
||||||
export const SITE_NAME = "Latosa® Escrima";
|
export const SITE_NAME = "Latosa® Escrima";
|
||||||
|
export const BASE_URL = process.env.SERVER_NAME ?? "latosa.cems.dev";
|
||||||
|
|||||||
@@ -1,25 +1,43 @@
|
|||||||
import { Role } from "@/types/types";
|
import { Role } from "@/types/types";
|
||||||
|
|
||||||
export default function hasPermissions(
|
type PermissionResult<T extends Record<string, readonly string[]>> = {
|
||||||
roles: Role[],
|
[K in keyof T]: {
|
||||||
permissions: { [key: string]: string[] },
|
[A in T[K][number]]: boolean;
|
||||||
) {
|
} & { all: boolean }; // Per-resource 'all'
|
||||||
|
} & { all: boolean }; // Global 'all'
|
||||||
|
|
||||||
|
// hasPermissions function with 'all' flags
|
||||||
|
export default function hasPermissions<
|
||||||
|
T extends Record<string, readonly string[]>,
|
||||||
|
>(roles: Role[], permissions: T): PermissionResult<T> {
|
||||||
|
// Build permissions set
|
||||||
const permissionsSet: Map<string, null> = new Map();
|
const permissionsSet: Map<string, null> = new Map();
|
||||||
for (const role of roles) {
|
for (const role of roles) {
|
||||||
if (!role.permissions) continue;
|
if (!role.permissions) continue;
|
||||||
for (const perm of role?.permissions) {
|
for (const perm of role.permissions) {
|
||||||
const key = perm.resource + ":" + perm.action;
|
const key = `${perm.resource}:${perm.action}`;
|
||||||
permissionsSet.set(key, null);
|
permissionsSet.set(key, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [perm, actions] of Object.entries(permissions)) {
|
// Build result
|
||||||
|
const result = { all: true } as PermissionResult<T>; // Initialize global 'all' as true
|
||||||
|
let globalAll = true; // Track global state
|
||||||
|
|
||||||
|
for (const resource in permissions) {
|
||||||
|
const actions = permissions[resource];
|
||||||
|
let resourceAll = true; // Track per-resource state
|
||||||
|
|
||||||
|
result[resource] = { all: true } as any; // Initialize resource object
|
||||||
for (const action of actions) {
|
for (const action of actions) {
|
||||||
if (!permissionsSet.has(perm + ":" + action)) {
|
const hasPerm = permissionsSet.has(`${resource}:${action}`);
|
||||||
return false;
|
(result[resource] as Record<string, boolean>)[action] = hasPerm;
|
||||||
}
|
resourceAll = resourceAll && hasPerm; // Update resource 'all'
|
||||||
}
|
}
|
||||||
|
result[resource].all = resourceAll; // Set resource 'all'
|
||||||
|
globalAll = globalAll && resourceAll; // Update global 'all'
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
result.all = globalAll; // Set global 'all'
|
||||||
|
return result as PermissionResult<T>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,3 +8,33 @@ export function cn(...inputs: ClassValue[]) {
|
|||||||
export function toTitleCase(str: string) {
|
export function toTitleCase(str: string) {
|
||||||
return str.replace(/\b\w/g, (char) => char.toUpperCase());
|
return str.replace(/\b\w/g, (char) => char.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace DiffUtils {
|
||||||
|
export function getDifferences<T extends object>(
|
||||||
|
obj1: T,
|
||||||
|
obj2: T,
|
||||||
|
): Partial<T> {
|
||||||
|
return Object.entries(obj2).reduce((diff, [key, value]) => {
|
||||||
|
if (
|
||||||
|
JSON.stringify(obj1[key as keyof T]) !==
|
||||||
|
JSON.stringify(obj2[key as keyof T])
|
||||||
|
) {
|
||||||
|
diff[key as keyof T] = value as T[keyof T];
|
||||||
|
}
|
||||||
|
return diff;
|
||||||
|
}, {} as Partial<T>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isEmpty<T extends object>(obj: T) {
|
||||||
|
return Object.keys(obj).length === 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make it globally available
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
(window as any).DiffUtils = DiffUtils;
|
||||||
|
} else {
|
||||||
|
(global as any).DiffUtils = DiffUtils;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DiffUtils;
|
||||||
|
|||||||
161
frontend/package-lock.json
generated
161
frontend/package-lock.json
generated
@@ -16,6 +16,7 @@
|
|||||||
"@radix-ui/react-collapsible": "^1.1.2",
|
"@radix-ui/react-collapsible": "^1.1.2",
|
||||||
"@radix-ui/react-dialog": "^1.1.4",
|
"@radix-ui/react-dialog": "^1.1.4",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.1.4",
|
"@radix-ui/react-dropdown-menu": "^2.1.4",
|
||||||
|
"@radix-ui/react-hover-card": "^1.1.6",
|
||||||
"@radix-ui/react-label": "^2.1.1",
|
"@radix-ui/react-label": "^2.1.1",
|
||||||
"@radix-ui/react-navigation-menu": "^1.2.3",
|
"@radix-ui/react-navigation-menu": "^1.2.3",
|
||||||
"@radix-ui/react-popover": "^1.1.4",
|
"@radix-ui/react-popover": "^1.1.4",
|
||||||
@@ -1354,6 +1355,166 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@radix-ui/react-hover-card": {
|
||||||
|
"version": "1.1.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-hover-card/-/react-hover-card-1.1.6.tgz",
|
||||||
|
"integrity": "sha512-E4ozl35jq0VRlrdc4dhHrNSV0JqBb4Jy73WAhBEK7JoYnQ83ED5r0Rb/XdVKw89ReAJN38N492BAPBZQ57VmqQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/primitive": "1.1.1",
|
||||||
|
"@radix-ui/react-compose-refs": "1.1.1",
|
||||||
|
"@radix-ui/react-context": "1.1.1",
|
||||||
|
"@radix-ui/react-dismissable-layer": "1.1.5",
|
||||||
|
"@radix-ui/react-popper": "1.2.2",
|
||||||
|
"@radix-ui/react-portal": "1.1.4",
|
||||||
|
"@radix-ui/react-presence": "1.1.2",
|
||||||
|
"@radix-ui/react-primitive": "2.0.2",
|
||||||
|
"@radix-ui/react-use-controllable-state": "1.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@radix-ui/react-hover-card/node_modules/@radix-ui/react-arrow": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-G+KcpzXHq24iH0uGG/pF8LyzpFJYGD4RfLjCIBfGdSLXvjLHST31RUiRVrupIBMvIppMgSzQ6l66iAxl03tdlg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-primitive": "2.0.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@radix-ui/react-hover-card/node_modules/@radix-ui/react-dismissable-layer": {
|
||||||
|
"version": "1.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.5.tgz",
|
||||||
|
"integrity": "sha512-E4TywXY6UsXNRhFrECa5HAvE5/4BFcGyfTyK36gP+pAW1ed7UTK4vKwdr53gAJYwqbfCWC6ATvJa3J3R/9+Qrg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/primitive": "1.1.1",
|
||||||
|
"@radix-ui/react-compose-refs": "1.1.1",
|
||||||
|
"@radix-ui/react-primitive": "2.0.2",
|
||||||
|
"@radix-ui/react-use-callback-ref": "1.1.0",
|
||||||
|
"@radix-ui/react-use-escape-keydown": "1.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@radix-ui/react-hover-card/node_modules/@radix-ui/react-popper": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.2.tgz",
|
||||||
|
"integrity": "sha512-Rvqc3nOpwseCyj/rgjlJDYAgyfw7OC1tTkKn2ivhaMGcYt8FSBlahHOZak2i3QwkRXUXgGgzeEe2RuqeEHuHgA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@floating-ui/react-dom": "^2.0.0",
|
||||||
|
"@radix-ui/react-arrow": "1.1.2",
|
||||||
|
"@radix-ui/react-compose-refs": "1.1.1",
|
||||||
|
"@radix-ui/react-context": "1.1.1",
|
||||||
|
"@radix-ui/react-primitive": "2.0.2",
|
||||||
|
"@radix-ui/react-use-callback-ref": "1.1.0",
|
||||||
|
"@radix-ui/react-use-layout-effect": "1.1.0",
|
||||||
|
"@radix-ui/react-use-rect": "1.1.0",
|
||||||
|
"@radix-ui/react-use-size": "1.1.0",
|
||||||
|
"@radix-ui/rect": "1.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@radix-ui/react-hover-card/node_modules/@radix-ui/react-portal": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-portal/-/react-portal-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-sn2O9k1rPFYVyKd5LAJfo96JlSGVFpa1fS6UuBJfrZadudiw5tAmru+n1x7aMRQ84qDM71Zh1+SzK5QwU0tJfA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-primitive": "2.0.2",
|
||||||
|
"@radix-ui/react-use-layout-effect": "1.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@radix-ui/react-hover-card/node_modules/@radix-ui/react-primitive": {
|
||||||
|
"version": "2.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.0.2.tgz",
|
||||||
|
"integrity": "sha512-Ec/0d38EIuvDF+GZjcMU/Ze6MxntVJYO/fRlCPhCaVUyPY9WTalHJw54tp9sXeJo3tlShWpy41vQRgLRGOuz+w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-slot": "1.1.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"@types/react-dom": "*",
|
||||||
|
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||||
|
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@types/react-dom": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@radix-ui/react-id": {
|
"node_modules/@radix-ui/react-id": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.0.tgz",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"@radix-ui/react-collapsible": "^1.1.2",
|
"@radix-ui/react-collapsible": "^1.1.2",
|
||||||
"@radix-ui/react-dialog": "^1.1.4",
|
"@radix-ui/react-dialog": "^1.1.4",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.1.4",
|
"@radix-ui/react-dropdown-menu": "^2.1.4",
|
||||||
|
"@radix-ui/react-hover-card": "^1.1.6",
|
||||||
"@radix-ui/react-label": "^2.1.1",
|
"@radix-ui/react-label": "^2.1.1",
|
||||||
"@radix-ui/react-navigation-menu": "^1.2.3",
|
"@radix-ui/react-navigation-menu": "^1.2.3",
|
||||||
"@radix-ui/react-popover": "^1.1.4",
|
"@radix-ui/react-popover": "^1.1.4",
|
||||||
|
|||||||
16
frontend/types/global.d.ts
vendored
Normal file
16
frontend/types/global.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// types/global.d.ts
|
||||||
|
declare namespace DiffUtils {
|
||||||
|
function getDifferences<T extends object>(obj1: T, obj2: T): Partial<T>;
|
||||||
|
function isEmpty<T extends object>(obj: T): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
DiffUtils: typeof DiffUtils;
|
||||||
|
}
|
||||||
|
namespace NodeJS {
|
||||||
|
interface Global {
|
||||||
|
DiffUtils: typeof DiffUtils;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user