-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
hideOnLandingPage
user setting
- Loading branch information
Showing
25 changed files
with
429 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
func GetSelectedDashboardIDFromCtx(ctx context.Context) (string, error) { | ||
dashboardId, ok := ctx.Value("dashboardId").(string) | ||
|
||
if !ok { | ||
return "", fmt.Errorf("failed to get dashboardId from context") | ||
} | ||
|
||
return dashboardId, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
model "github.com/satont/twir/libs/gomodels" | ||
) | ||
|
||
func GetUserModelFromCtx(ctx context.Context) (model.Users, error) { | ||
user, ok := ctx.Value("dbUser").(model.Users) | ||
if !ok { | ||
return model.Users{}, fmt.Errorf("failed to get user from context") | ||
} | ||
|
||
return user, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package users | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
"github.com/satont/twir/apps/api/internal/helpers" | ||
"github.com/satont/twir/apps/api/internal/impl_deps" | ||
"github.com/satont/twir/libs/grpc/generated/api/users" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
) | ||
|
||
type Users struct { | ||
*impl_deps.Deps | ||
} | ||
|
||
func (c *Users) UsersRegenerateApiKey( | ||
ctx context.Context, | ||
req *users.RegenerateApiKeyRequest, | ||
) (*emptypb.Empty, error) { | ||
user, err := helpers.GetUserModelFromCtx(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get user from context: %w", err) | ||
} | ||
|
||
user.ApiKey = uuid.New().String() | ||
|
||
if err := c.Db.Save(&user).Error; err != nil { | ||
return nil, fmt.Errorf("failed to save user: %w", err) | ||
} | ||
|
||
return &emptypb.Empty{}, nil | ||
} | ||
|
||
func (c *Users) UsersUpdate(ctx context.Context, req *users.UpdateUserRequest) ( | ||
*emptypb.Empty, | ||
error, | ||
) { | ||
user, err := helpers.GetUserModelFromCtx(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get user from context: %w", err) | ||
} | ||
|
||
query := c.Db.WithContext(ctx).Model(&user) | ||
|
||
// everything bellow working like a PATCH http request | ||
if req.HideOnLandingPage != nil { | ||
user.HideOnLandingPage = *req.HideOnLandingPage | ||
} | ||
|
||
if err := query.Save(&user).Error; err != nil { | ||
return nil, fmt.Errorf("failed to update user: %w", err) | ||
} | ||
|
||
c.SessionManager.Put(ctx, "dbUser", user) | ||
|
||
return &emptypb.Empty{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/vue-query'; | ||
import type { UpdateUserRequest } from '@twir/grpc/generated/api/api/users'; | ||
|
||
import { profileQueryOptions } from '@/api/auth'; | ||
import { protectedApiClient } from '@/api/twirp'; | ||
|
||
export const useUser = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return { | ||
useRegenerateApiKey: () => useMutation({ | ||
mutationKey: ['userRegenerateApiKey'], | ||
mutationFn: async () => { | ||
const call = await protectedApiClient.usersRegenerateApiKey({}); | ||
return call.response; | ||
}, | ||
async onSuccess() { | ||
await queryClient.invalidateQueries(profileQueryOptions.queryKey); | ||
}, | ||
}), | ||
useUpdate: () => useMutation({ | ||
mutationKey: ['userUpdate'], | ||
mutationFn: async (data: UpdateUserRequest) => { | ||
const call = await protectedApiClient.usersUpdate(data); | ||
return call.response; | ||
}, | ||
async onSuccess() { | ||
await queryClient.invalidateQueries(profileQueryOptions.queryKey); | ||
}, | ||
}), | ||
}; | ||
}; |
61 changes: 61 additions & 0 deletions
61
frontend/dashboard/src/layout/dropdowns/dropdownProfile.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script setup lang="ts"> | ||
import { type DropdownOption, NAvatar, NButton, NDropdown, NSpin } from 'naive-ui'; | ||
import { h } from 'vue'; | ||
import DropdownBody from './profile/body.vue'; | ||
import DropdownFooter from './profile/footer.vue'; | ||
import DropdownHeader from './profile/header.vue'; | ||
import { useProfile } from '@/api'; | ||
const { data: profileData, isLoading: isProfileLoading } = useProfile(); | ||
const profileOptions: DropdownOption[] = [ | ||
{ | ||
key: 'header', | ||
type: 'render', | ||
render: () => h(DropdownHeader), | ||
}, | ||
{ | ||
key: 'header-divider', | ||
type: 'divider', | ||
}, | ||
{ | ||
key: 'body', | ||
type: 'render', | ||
render: () => h(DropdownBody), | ||
}, | ||
{ | ||
key: 'body-divider', | ||
type: 'divider', | ||
}, | ||
{ | ||
key: 'footer', | ||
type: 'render', | ||
render: () => h(DropdownFooter), | ||
}, | ||
]; | ||
</script> | ||
|
||
<template> | ||
<n-dropdown trigger="click" :options="profileOptions" size="large" style="width: 400px;"> | ||
<n-button text> | ||
<n-spin v-if="isProfileLoading" size="small" /> | ||
<div v-else class="profile"> | ||
<n-avatar | ||
size="small" | ||
:src="profileData?.avatar" | ||
round | ||
/> | ||
</div> | ||
</n-button> | ||
</n-dropdown> | ||
</template> | ||
|
||
<style scoped> | ||
.profile { | ||
display: flex; | ||
gap: 5px; | ||
align-items: center; | ||
} | ||
</style> |
46 changes: 0 additions & 46 deletions
46
frontend/dashboard/src/layout/dropdowns/dropdownProfileOptions.vue
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.