feat(worker): add logout + replace admin-only settings with Account screen
The Instellingen tab was activity management, which Phase 2 made admin-only — workers saw add/edit/delete controls that all 403. Replace it with an Account tab showing the signed-in name/email (via /api/me) and an Uitloggen button (wires the existing AuthContext signOut). Activity management belongs to the Phase 3 admin app, so the worker client drops the Settings screen and its now-unused activity-mutation hooks (useActivities read stays). Products affected: SoleLog worker client (apps/worker).
This commit is contained in:
@@ -1,51 +1,12 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import type { Activity, CreateActivityInput, UpdateActivityInput } from '@solelog/shared';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { Activity } from '@solelog/shared';
|
||||
import { apiFetch } from '../lib/api';
|
||||
|
||||
// Activities are read-only in the worker client; managing them is admin-only
|
||||
// and lives in the Phase 3 admin app.
|
||||
export function useActivities() {
|
||||
return useQuery({
|
||||
queryKey: ['activities'],
|
||||
queryFn: () => apiFetch<Activity[]>('/api/activities'),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateActivity() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (input: CreateActivityInput) =>
|
||||
apiFetch<Activity>('/api/activities', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['activities'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateActivity() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, input }: { id: number; input: UpdateActivityInput }) =>
|
||||
apiFetch<Activity>(`/api/activities/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['activities'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteActivity() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) =>
|
||||
apiFetch<{ success: true }>(`/api/activities/${id}`, { method: 'DELETE' }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['activities'] });
|
||||
// Deleting an activity cascades to its work sessions on the server.
|
||||
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
11
apps/worker/src/api/me.ts
Normal file
11
apps/worker/src/api/me.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { MeResponse } from '@solelog/shared';
|
||||
import { apiFetch } from '../lib/api';
|
||||
|
||||
// The signed-in user (id, email, name). Used by the Account screen.
|
||||
export function useMe() {
|
||||
return useQuery({
|
||||
queryKey: ['me'],
|
||||
queryFn: () => apiFetch<MeResponse>('/api/me'),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user