Skip to content

Commit

Permalink
Fix issue where redirect still happened after failed group creation (#…
Browse files Browse the repository at this point in the history
…1314)

* Fix issue when redirect still happened after failed group creation

* unrelatedly stop the button going grey on hover
  • Loading branch information
theosanderson committed Mar 10, 2024
1 parent b6454ae commit 838aad2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
9 changes: 5 additions & 4 deletions website/src/components/User/GroupCreationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const InnerGroupCreationForm: FC<GroupManagerProps> = ({ clientConfig, accessTok
const { createGroup } = useGroupCreation({
clientConfig,
accessToken,
setErrorMessage,
});

const handleCreateGroup = async (e: FormEvent<HTMLFormElement>) => {
Expand All @@ -43,15 +42,17 @@ const InnerGroupCreationForm: FC<GroupManagerProps> = ({ clientConfig, accessTok
return false;
}

await createGroup({
const result = await createGroup({
groupName,
institution,
contactEmail,
address: { line1, line2, city, postalCode, state, country },
});

if (errorMessage === undefined) {
if (result.succeeded) {
window.location.href = routes.groupOverviewPage(groupName);
} else {
setErrorMessage(result.errorMessage);
}
};

Expand Down Expand Up @@ -212,7 +213,7 @@ const CountryInput = () => (
autoComplete='country-name'
className='block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:max-w-xs sm:text-sm sm:leading-6'
>
<option>Choose a country...</option>
<option>{chooseCountry}</option>
{listOfCountries.map((country) => (
<option key={country}>{country}</option>
))}
Expand Down
27 changes: 18 additions & 9 deletions website/src/hooks/useGroupOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ export const useGroupPageHooks = ({
};
};

export const useGroupCreation = ({ clientConfig, accessToken, setErrorMessage }: UseGroupOperationsProps) => {
export const useGroupCreation = ({
clientConfig,
accessToken,
}: {
clientConfig: ClientConfig;
accessToken: string;
}) => {
const { zodios } = useGroupManagementClient(clientConfig);

const createGroup = useCallback(
async (group: Group) => {
await callCreateGroup(accessToken, setErrorMessage, zodios)(group);
const result = await callCreateGroup(accessToken, zodios)(group);
return result;
},
[accessToken, setErrorMessage, zodios],
[accessToken, zodios],
);

return {
Expand Down Expand Up @@ -98,19 +105,21 @@ export const useGroupManagementClient = (clientConfig: ClientConfig) => {
};
};

function callCreateGroup(
accessToken: string,
openErrorFeedback: (message: string | undefined) => void,
zodios: ZodiosInstance<typeof groupManagementApi>,
) {
function callCreateGroup(accessToken: string, zodios: ZodiosInstance<typeof groupManagementApi>) {
return async (group: Group) => {
try {
await zodios.createGroup(group, {
headers: createAuthorizationHeader(accessToken),
});
return {
succeeded: true,
};
} catch (error) {
const message = `Failed to create group: ${stringifyMaybeAxiosError(error)}`;
openErrorFeedback(message);
return {
succeeded: false,
errorMessage: message,
};
}
};
}
Expand Down
3 changes: 3 additions & 0 deletions website/src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ a {

.loculusColor{
background: theme('colors.main');
&:hover {
background: theme('colors.primary.700');
}
}

.offCanvasTransform {
Expand Down

0 comments on commit 838aad2

Please sign in to comment.