Added rules frontend

This commit is contained in:
2026-04-08 18:11:56 +02:00
parent 1978a31cbf
commit 88323ed4fe
23 changed files with 1412 additions and 81 deletions
+56
View File
@@ -0,0 +1,56 @@
import { makeApiUrl } from '.';
import type { CreateForwardRuleRequest, ForwardRule } from './types/site';
export const getForwardRules = async (siteId: string): Promise<ForwardRule[]> => {
const response = await fetch(makeApiUrl(`/sites/${siteId}/forward-rules`), {
method: 'GET',
});
if (!response.ok) {
throw new Error('Failed to fetch forward rules');
}
return response.json();
};
export const createForwardRule = async (
siteId: string,
data: CreateForwardRuleRequest
): Promise<ForwardRule> => {
const response = await fetch(makeApiUrl(`/sites/${siteId}/forward-rules`), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error('Failed to create forward rule');
}
return response.json();
};
export const updateForwardRule = async (
siteId: string,
ruleId: string,
data: CreateForwardRuleRequest
): Promise<ForwardRule> => {
const response = await fetch(makeApiUrl(`/sites/${siteId}/forward-rules/${ruleId}`), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error('Failed to update forward rule');
}
return response.json();
};
export const deleteForwardRule = async (siteId: string, ruleId: string): Promise<void> => {
const response = await fetch(makeApiUrl(`/sites/${siteId}/forward-rules/${ruleId}`), {
method: 'DELETE',
});
if (!response.ok) {
throw new Error('Failed to delete forward rule');
}
};