MCPcopy Create free account
hub / github.com/dailydotdev/apps / useSquadCreate

Function useSquadCreate

packages/shared/src/hooks/squads/useSquadCreate.ts:32–79  ·  view source on GitHub ↗
({
  onSuccess,
  retryWithRandomizedHandle,
} = {})

Source from the content-addressed store, hash-verified

30const HANDLE_ERROR = 'handle is already used';
31
32export const useSquadCreate: CustomHook = ({
33 onSuccess,
34 retryWithRandomizedHandle,
35} = {}) => {
36 const { addSquad } = useBoot();
37 const { logEvent } = useLogContext();
38 const { displayToast } = useToastNotification();
39 const { completeAction } = useActions();
40
41 const { mutateAsync: onCreateSquad, isPending: isLoading } = useMutation({
42 mutationFn: createSquad,
43 onSuccess: (squad) => {
44 logEvent({
45 event_name: LogEvent.CompleteSquadCreation,
46 });
47
48 addSquad(squad);
49 completeAction(ActionType.CreateSquad);
50
51 if (onSuccess) {
52 onSuccess(squad);
53 } else {
54 router.replace(squad.permalink);
55 }
56 },
57 onError: (error: ApiErrorResult, variables) => {
58 const result = parseOrDefault<Record<string, string>>(
59 error?.response?.errors?.[0]?.message,
60 );
61
62 if (
63 retryWithRandomizedHandle &&
64 typeof result === 'object' &&
65 result.handle === HANDLE_ERROR
66 ) {
67 onCreateSquad({
68 ...variables,
69 handle: `${variables.handle}${getRandom4Digits()}`,
70 });
71 return;
72 }
73
74 displayToast(typeof result === 'object' ? result.handle : DEFAULT_ERROR);
75 },
76 });
77
78 return { onCreateSquad, isLoading };
79};

Callers 1

NewSquadFunction · 0.90

Calls 11

useBootFunction · 0.90
useLogContextFunction · 0.90
useToastNotificationFunction · 0.90
useActionsFunction · 0.90
parseOrDefaultFunction · 0.90
getRandom4DigitsFunction · 0.90
logEventFunction · 0.85
addSquadFunction · 0.85
displayToastFunction · 0.85
replaceMethod · 0.80
onSuccessFunction · 0.50

Tested by

no test coverage detected