Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
// output: 'standalone',
/* config options here */
// 외부 이미지 도메인 허용 설정 추가
images: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@radix-ui/react-slot": "^1.2.2",
"@radix-ui/react-switch": "^1.2.4",
"@radix-ui/react-toggle": "^1.1.9",
"@radix-ui/react-tooltip": "^1.2.8",
"@tailwindcss/postcss": "^4.0.6",
"axios": "^1.9.0",
"class-variance-authority": "^0.7.1",
Expand Down
72 changes: 54 additions & 18 deletions src/entities/user/model/use-user-profile-query.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { sendGTMEvent } from '@next/third-parties/google';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import {
getUserProfile,
patchAutoMatching,
} from '@/entities/user/api/get-user-profile';
import type {
GetUserProfileResponse,
PatchAutoMatchingParams,
} from '@/entities/user/api/types';
import type { GetUserProfileResponse } from '@/entities/user/api/types';
import { hashValue } from '@/shared/lib/hash';

export const useUserProfileQuery = (memberId: number) => {
Expand All @@ -19,23 +16,62 @@ export const useUserProfileQuery = (memberId: number) => {
});
};

export interface PatchAutoMatchingParams {
memberId: number;
autoMatching: boolean;
}

export const usePatchAutoMatchingMutation = () => {
return useMutation<void, unknown, PatchAutoMatchingParams>({
const qc = useQueryClient();

return useMutation<
void,
unknown,
PatchAutoMatchingParams,
{ prev?: unknown }
>({
mutationFn: patchAutoMatching,
onSuccess: (_, variables) => {
if (variables.autoMatching) {
sendGTMEvent({
event: 'custom_member_study_toggle_on',
dl_timestamp: new Date().toISOString(),
dl_member_id: hashValue(String(variables.memberId)),
});
} else {
sendGTMEvent({
event: 'custom_member_study_toggle_off',
dl_timestamp: new Date().toISOString(),
dl_member_id: hashValue(String(variables.memberId)),

onMutate: async ({ memberId, autoMatching }) => {
await qc.cancelQueries({ queryKey: ['userProfile', memberId] });
const prev = qc.getQueryData(['userProfile', memberId]);
if (prev && typeof prev === 'object') {
qc.setQueryData(['userProfile', memberId], {
...(prev as any),
autoMatching,
});
}

return { prev };
},

onError: (_err, { memberId }, ctx) => {
if (ctx?.prev) {
qc.setQueryData(['userProfile', memberId], ctx.prev);
}
},

onSuccess: async (_data, { memberId, autoMatching }) => {
await qc.invalidateQueries({ queryKey: ['userProfile', memberId] });

await qc.invalidateQueries({
predicate: (q) =>
Array.isArray(q.queryKey) && q.queryKey[0] === 'weeklyParticipation',
});

await qc.invalidateQueries({
predicate: (q) =>
Array.isArray(q.queryKey) &&
q.queryKey[0] === 'weeklyReservationMembers',
});

sendGTMEvent({
event: autoMatching
? 'custom_member_study_toggle_on'
: 'custom_member_study_toggle_off',
dl_timestamp: new Date().toISOString(),
dl_member_id: hashValue(String(memberId)),
});
},
});
};
Loading