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

Function useSquadCreate

packages/shared/src/hooks/squads/useSquadCreate.ts:32–86  ·  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, variables) => {
44 logEvent({
45 event_name: LogEvent.CompleteSquadCreation,
46 ...(variables.company && {
47 extra: JSON.stringify({ company: true }),
48 }),
49 });
50
51 addSquad(squad);
52 completeAction(ActionType.CreateSquad);
53
54 if (onSuccess) {
55 onSuccess(squad);
56 } else {
57 router.replace(squad.permalink);
58 }
59 },
60 onError: (error: ApiErrorResult, variables) => {
61 const result = parseOrDefault<Record<string, string>>(
62 error?.response?.errors?.[0]?.message,
63 );
64
65 if (
66 retryWithRandomizedHandle &&
67 typeof result === 'object' &&
68 result.handle === HANDLE_ERROR
69 ) {
70 onCreateSquad({
71 ...variables,
72 handle: `${variables.handle}${getRandom4Digits()}`,
73 });
74 return;
75 }
76
77 displayToast(
78 typeof result === 'object' && result.handle
79 ? result.handle
80 : DEFAULT_ERROR,
81 );
82 },
83 });
84
85 return { onCreateSquad, isLoading };
86};

Callers 2

CompanyPageCreateFunction · 0.90
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