frontPanel/src/api/promocode.ts

28 lines
762 B
TypeScript
Raw Normal View History

2024-05-13 13:24:41 +00:00
import { makeRequest } from "@api/makeRequest";
2024-04-09 10:41:32 +00:00
import { parseAxiosError } from "@utils/parse-error";
2024-03-22 19:01:48 +00:00
2024-05-13 13:24:41 +00:00
type ActivatePromocodeRequest = { codeword: string } | { fastLink: string };
type ActivatePromocodeResponse = { greetings: string };
2024-03-22 19:01:48 +00:00
2024-05-13 13:24:41 +00:00
const API_URL = process.env.REACT_APP_DOMAIN + "/codeword/promocode";
export const activatePromocode = async (promocode: string) => {
2024-03-22 19:01:48 +00:00
try {
const response = await makeRequest<
2024-05-13 13:24:41 +00:00
ActivatePromocodeRequest,
ActivatePromocodeResponse
2024-03-22 19:01:48 +00:00
>({
method: "POST",
2024-05-13 13:24:41 +00:00
url: API_URL + "/activate",
2024-04-09 10:41:32 +00:00
body: { codeword: promocode },
2024-05-13 13:24:41 +00:00
contentType: true,
2024-03-22 19:01:48 +00:00
});
return response.greetings;
2024-04-09 10:41:32 +00:00
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
throw new Error(error);
2024-03-22 19:01:48 +00:00
}
2024-05-13 13:24:41 +00:00
};