0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

refactor(console): remove api path leading slash

This commit is contained in:
Gao Sun 2023-02-10 01:34:23 +08:00
parent 6b09da2f5d
commit 1d7f22debf
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
58 changed files with 90 additions and 87 deletions
.husky
packages/console/src
components
ApplicationName
AuditLogTable
components/ApplicationSelector
index.tsx
RoleScopesTransfer/components/SourceScopesBox
RoleUsersTransfer/components/SourceUsersBox
UserName
UserRolesTransfer/components/SourceRolesBox
hooks
mdx-components/UriInputField
pages
ApiResourceDetails
ApiResourcePermissions
components/CreatePermissionModal
index.tsx
ApiResourceSettings
index.tsx
ApiResources
components/CreateForm
index.tsx
ApplicationDetails
Applications
components/CreateForm
index.tsx
AuditLogDetails
ConnectorDetails
components
index.tsx
Connectors/components
ConnectorTypeColumn
CreateForm
Guide
SignInExperienceSetupNotice
Dashboard
GetStarted
RoleDetails
RolePermissions
components/AssignPermissionsModal
index.tsx
RoleSettings
RoleUsers
components/AssignUsersModal
index.tsx
index.tsx
Roles
components/CreateRoleForm
index.tsx
Settings/components
SignInExperience
components
index.tsx
tabs/Others
LanguagesForm.tsx
components/ManageLanguage/LanguageEditor
UserDetails
UserRoles
components/AssignRolesModal
index.tsx
UserSettings
components/UserSocialIdentities
index.tsx
components/ResetPasswordForm
index.tsx
Users
components/CreateForm
index.tsx

View file

@ -1,4 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
FORCE_COLOR=1 pnpm -r --filter "[HEAD]" precommit
# Keep concurrency 1 to avoid lint-staged issue
# Which may cause ALL your work LOST WITHOUT STASH
FORCE_COLOR=1 pnpm -r --workspace-concurrency 1 --filter "[HEAD]" precommit

View file

@ -14,7 +14,7 @@ type Props = {
const ApplicationName = ({ applicationId, isLink = false }: Props) => {
const isAdminConsole = applicationId === adminConsoleApplicationId;
const { data } = useSWR<Application>(!isAdminConsole && `/api/applications/${applicationId}`);
const { data } = useSWR<Application>(!isAdminConsole && `api/applications/${applicationId}`);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const name = (isAdminConsole ? <>Admin Console ({t('system_app')})</> : data?.name) ?? '-';

View file

@ -12,7 +12,7 @@ type Props = {
const ApplicationSelector = ({ value, onChange }: Props) => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data } = useSWR<Application[]>('/api/applications');
const { data } = useSWR<Application[]>('api/applications');
const options =
data?.map(({ id, name }) => ({
value: id,

View file

@ -34,7 +34,7 @@ const AuditLogTable = ({ userId, className }: Props) => {
applicationId: '',
});
const url = buildUrl('/api/logs', {
const url = buildUrl('api/logs', {
page: String(page),
page_size: String(pageSize),
...conditional(event && { logType: event }),

View file

@ -29,10 +29,10 @@ const SourceScopesBox = ({ roleId, selectedScopes, onChange }: Props) => {
const { data: allResources, error: fetchAllResourcesError } = useSWR<
ResourceResponse[],
RequestError
>('/api/resources?includeScopes=true');
>('api/resources?includeScopes=true');
const { data: roleScopes, error: fetchRoleScopesError } = useSWR<Scope[], RequestError>(
roleId && `/api/roles/${roleId}/scopes`
roleId && `api/roles/${roleId}/scopes`
);
const isLoading =

View file

@ -33,7 +33,7 @@ const SourceUsersBox = ({ roleId, selectedUsers, onChange }: Props) => {
const [keyword, setKeyword] = useState('');
const debounce = useDebounce();
const url = buildUrl('/api/users', {
const url = buildUrl('api/users', {
excludeRoleId: roleId,
hideAdminUser: String(true),
page: String(page),

View file

@ -14,7 +14,7 @@ type Props = {
};
const UserName = ({ userId, isLink = false }: Props) => {
const { data, error } = useSWR<User, RequestError>(`/api/users/${userId}`);
const { data, error } = useSWR<User, RequestError>(`api/users/${userId}`);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const isLoading = !data && !error;

View file

@ -35,7 +35,7 @@ const SourceRolesBox = ({ userId, selectedRoles, onChange }: Props) => {
const debounce = useDebounce();
const url = buildUrl('/api/roles', {
const url = buildUrl('api/roles', {
excludeUserId: userId,
page: String(page),
page_size: String(pageSize),

View file

@ -44,6 +44,7 @@ const useApi = ({ hideErrorToast }: Props = {}) => {
const api = useMemo(
() =>
ky.create({
prefixUrl: window.location.origin,
timeout: requestTimeout,
hooks: {
beforeError: hideErrorToast

View file

@ -12,12 +12,12 @@ const useConfigs = () => {
data: configs,
error,
mutate,
} = useSWR<AdminConsoleData, RequestError>(shouldFetch && '/api/configs/admin-console');
} = useSWR<AdminConsoleData, RequestError>(shouldFetch && 'api/configs/admin-console');
const api = useApi();
const updateConfigs = async (json: Partial<AdminConsoleData>) => {
const updatedConfigs = await api
.patch('/api/configs/admin-console', {
.patch('api/configs/admin-console', {
json,
})
.json<AdminConsoleData>();

View file

@ -7,7 +7,7 @@ import { getConnectorGroups } from '@/pages/Connectors/utils';
// Group connectors by target
const useConnectorGroups = () => {
const { data, ...rest } = useSWR<ConnectorResponse[], RequestError>('/api/connectors');
const { data, ...rest } = useSWR<ConnectorResponse[], RequestError>('api/connectors');
const groups = useMemo(() => {
if (!data) {

View file

@ -6,7 +6,7 @@ import useSWR from 'swr';
import type { RequestError } from './use-api';
const useConnectorInUse = () => {
const { data } = useSWR<SignInExperience, RequestError>('/api/sign-in-exp');
const { data } = useSWR<SignInExperience, RequestError>('api/sign-in-exp');
const isConnectorInUse = useCallback(
(connector?: ConnectorResponse) => {

View file

@ -5,7 +5,7 @@ import useSWR from 'swr';
import type { RequestError } from './use-api';
const useEnabledConnectorTypes = () => {
const { data: connectors } = useSWR<ConnectorResponse[], RequestError>('/api/connectors');
const { data: connectors } = useSWR<ConnectorResponse[], RequestError>('api/connectors');
const enabledConnectorTypes = useMemo(
() => connectors?.map(({ type }) => type) ?? [],

View file

@ -14,7 +14,7 @@ const useUiLanguages = () => {
data: customPhraseList,
error,
mutate,
} = useSWR<CustomPhraseResponse[], RequestError>('/api/custom-phrases');
} = useSWR<CustomPhraseResponse[], RequestError>('api/custom-phrases');
const languages = useMemo(
() =>
@ -31,7 +31,7 @@ const useUiLanguages = () => {
const addLanguage = useCallback(
async (languageTag: LanguageTag) => {
await api.put(`/api/custom-phrases/${languageTag}`, { json: {} });
await api.put(`api/custom-phrases/${languageTag}`, { json: {} });
await mutate();
},
[api, mutate]

View file

@ -36,7 +36,7 @@ const useUserPreferences = () => {
const userId = useLogtoUserId();
const shouldFetch = isAuthenticated && !authError && userId;
const { data, mutate, error } = useSWR<unknown, RequestError>(
shouldFetch && `/api/users/${userId}/custom-data`
shouldFetch && `api/users/${userId}/custom-data`
);
const api = useApi();
@ -62,7 +62,7 @@ const useUserPreferences = () => {
}
const updated = await api
.patch(`/api/users/${userId}/custom-data`, {
.patch(`api/users/${userId}/custom-data`, {
json: {
customData: {
[key]: {

View file

@ -36,7 +36,7 @@ const UriInputField = ({ appId, name, title, isSingle = false }: Props) => {
formState: { isSubmitting },
} = methods;
const { data, mutate } = useSWR<Application, RequestError>(`/api/applications/${appId}`);
const { data, mutate } = useSWR<Application, RequestError>(`api/applications/${appId}`);
const ref = useRef<HTMLDivElement>(null);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
@ -44,7 +44,7 @@ const UriInputField = ({ appId, name, title, isSingle = false }: Props) => {
const onSubmit = async (value: string[]) => {
const updatedApp = await api
.patch(`/api/applications/${appId}`, {
.patch(`api/applications/${appId}`, {
json: {
oidcClientMetadata: {
[name]: value.filter(Boolean),

View file

@ -34,7 +34,7 @@ const CreatePermissionModal = ({ resourceId, onClose }: Props) => {
}
const createdScope = await api
.post(`/api/resources/${resourceId}/scopes`, { json: formData })
.post(`api/resources/${resourceId}/scopes`, { json: formData })
.json<Scope>();
onClose(createdScope);

View file

@ -34,7 +34,7 @@ const ApiResourcePermissions = () => {
const { data, error, mutate } = useSWR<[ScopeResponse[], number], RequestError>(
resourceId &&
buildUrl(`/api/resources/${resourceId}/scopes`, {
buildUrl(`api/resources/${resourceId}/scopes`, {
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),
@ -57,7 +57,7 @@ const ApiResourcePermissions = () => {
setIsDeleting(true);
try {
await api.delete(`/api/resources/${resourceId}/scopes/${scopeToBeDeleted.id}`);
await api.delete(`api/resources/${resourceId}/scopes/${scopeToBeDeleted.id}`);
toast.success(t('api_resource_details.permission.deleted', { name: scopeToBeDeleted.name }));
await mutate();
setScopeToBeDeleted(undefined);

View file

@ -38,7 +38,7 @@ const ApiResourceSettings = () => {
}
const updatedApiResource = await api
.patch(`/api/resources/${resource.id}`, { json: formData })
.patch(`api/resources/${resource.id}`, { json: formData })
.json<Resource>();
reset(updatedApiResource);
onResourceUpdated(updatedApiResource);

View file

@ -33,7 +33,7 @@ const ApiResourceDetails = () => {
const { id } = useParams();
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const navigate = useNavigate();
const { data, error, mutate } = useSWR<Resource, RequestError>(id && `/api/resources/${id}`);
const { data, error, mutate } = useSWR<Resource, RequestError>(id && `api/resources/${id}`);
const isLoading = !data && !error;
const theme = useTheme();
const Icon = theme === AppearanceMode.LightMode ? ApiResource : ApiResourceDark;
@ -59,7 +59,7 @@ const ApiResourceDetails = () => {
setIsDeleting(true);
try {
await api.delete(`/api/resources/${data.id}`);
await api.delete(`api/resources/${data.id}`);
toast.success(t('api_resource_details.api_resource_deleted', { name: data.name }));
navigate(`/api-resources`);
} finally {

View file

@ -33,7 +33,7 @@ const CreateForm = ({ onClose }: Props) => {
return;
}
const createdApiResource = await api.post('/api/resources', { json: data }).json<Resource>();
const createdApiResource = await api.post('api/resources', { json: data }).json<Resource>();
onClose?.(createdApiResource);
});

View file

@ -42,7 +42,7 @@ const ApiResources = () => {
page: 1,
});
const url = buildUrl('/api/resources', {
const url = buildUrl('api/resources', {
page: String(page),
page_size: String(pageSize),
});

View file

@ -43,7 +43,7 @@ const ApplicationDetails = () => {
const { id } = useParams();
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data, error, mutate } = useSWR<ApplicationResponse, RequestError>(
id && `/api/applications/${id}`
id && `api/applications/${id}`
);
const { data: oidcConfig, error: fetchOidcConfigError } = useSWR<
SnakeCaseOidcConfig,
@ -79,7 +79,7 @@ const ApplicationDetails = () => {
}
await api
.patch(`/api/applications/${data.id}`, {
.patch(`api/applications/${data.id}`, {
json: {
...formData,
oidcClientMetadata: {
@ -108,7 +108,7 @@ const ApplicationDetails = () => {
}
try {
await api.delete(`/api/applications/${data.id}`);
await api.delete(`api/applications/${data.id}`);
setIsDeleted(true);
setIsDeleting(false);
setIsDeleteFormOpen(false);

View file

@ -55,7 +55,7 @@ const CreateForm = ({ onClose }: Props) => {
return;
}
const createdApp = await api.post('/api/applications', { json: data }).json<Application>();
const createdApp = await api.post('api/applications', { json: data }).json<Application>();
setCreatedApp(createdApp);
setIsGetStartedModalOpen(true);
void updateConfigs({ applicationCreated: true });

View file

@ -39,7 +39,7 @@ const Applications = () => {
page: 1,
});
const url = buildUrl('/api/applications', {
const url = buildUrl('api/applications', {
page: String(page),
page_size: String(pageSize),
});

View file

@ -30,8 +30,8 @@ const AuditLogDetails = () => {
const { id, logId } = useParams();
const { pathname } = useLocation();
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data, error } = useSWR<Log, RequestError>(logId && `/api/logs/${logId}`);
const { data: userData } = useSWR<User, RequestError>(id && `/api/users/${id}`);
const { data, error } = useSWR<Log, RequestError>(logId && `api/logs/${logId}`);
const { data: userData } = useSWR<User, RequestError>(id && `api/users/${id}`);
const isLoading = !data && !error;

View file

@ -83,7 +83,7 @@ const ConnectorContent = ({ isDeleted, connectorData, onConnectorUpdated }: Prop
const body = connectorData.isStandard ? standardConnectorPayload : payload;
const updatedConnector = await api
.patch(`/api/connectors/${connectorData.id}`, {
.patch(`api/connectors/${connectorData.id}`, {
json: body,
})
.json<ConnectorResponse>();

View file

@ -18,7 +18,7 @@ type Props = {
const ConnectorTabs = ({ target, connectorId }: Props) => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data: connectors } = useSWR<ConnectorResponse[]>(`/api/connectors?target=${target}`);
const { data: connectors } = useSWR<ConnectorResponse[]>(`api/connectors?target=${target}`);
if (!connectors) {
return null;

View file

@ -69,7 +69,7 @@ const SenderTester = ({ connectorId, connectorType, config, className }: Props)
const data = { config: result.data, ...(isSms ? { phone: sendTo } : { email: sendTo }) };
await api.post(`/api/connectors/${connectorId}/test`, { json: data }).json();
await api.post(`api/connectors/${connectorId}/test`, { json: data }).json();
setShowTooltip(true);
});

View file

@ -47,10 +47,10 @@ const ConnectorDetails = () => {
const [isSetupOpen, setIsSetupOpen] = useState(false);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data, error, mutate } = useSWR<ConnectorResponse, RequestError>(
connectorId && `/api/connectors/${connectorId}`
connectorId && `api/connectors/${connectorId}`
);
const { data: connectorFactory } = useSWR<ConnectorFactoryResponse>(
data?.isStandard && `/api/connector-factories/${data.connectorId}`
data?.isStandard && `api/connector-factories/${data.connectorId}`
);
const { isConnectorInUse } = useConnectorInUse();
const inUse = isConnectorInUse(data);
@ -79,12 +79,12 @@ const ConnectorDetails = () => {
return;
}
await api.delete(`/api/connectors/${connectorId}`).json<ConnectorResponse>();
await api.delete(`api/connectors/${connectorId}`).json<ConnectorResponse>();
setIsDeleted(true);
toast.success(t('connector_details.connector_deleted'));
await mutateGlobal('/api/connectors');
await mutateGlobal('api/connectors');
navigate(getConnectorsPathname(isSocial), {
replace: true,

View file

@ -22,7 +22,7 @@ const ConnectorTypeColumn = ({ connectorGroup: { type, connectors } }: Props) =>
const firstStandardConnector = standardConnectors[0];
const { data: connectorFactory } = useSWR<ConnectorFactoryResponse>(
firstStandardConnector && `/api/connector-factories/${firstStandardConnector.connectorId}`
firstStandardConnector && `api/connector-factories/${firstStandardConnector.connectorId}`
);
if (!firstStandardConnector) {

View file

@ -29,11 +29,11 @@ const CreateForm = ({ onClose, isOpen: isFormOpen, type }: Props) => {
const { data: existingConnectors, error: connectorsError } = useSWR<
ConnectorResponse[],
RequestError
>('/api/connectors');
>('api/connectors');
const { data: factories, error: factoriesError } = useSWR<
ConnectorFactoryResponse[],
RequestError
>('/api/connector-factories');
>('api/connector-factories');
const isLoading = !factories && !existingConnectors && !connectorsError && !factoriesError;
const [activeGroupId, setActiveGroupId] = useState<string>();
const [activeFactoryId, setActiveFactoryId] = useState<string>();

View file

@ -84,7 +84,7 @@ const Guide = ({ connector, onClose }: Props) => {
: basePayload;
const createdConnector = await api
.post('/api/connectors', {
.post('api/connectors', {
json: payload,
})
.json<ConnectorResponse>();

View file

@ -10,7 +10,7 @@ import * as styles from './index.module.scss';
const SignInExperienceSetupNotice = () => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data: connectors } = useSWR<ConnectorResponse[]>('/api/connectors');
const { data: connectors } = useSWR<ConnectorResponse[]>('api/connectors');
const {
data: { connectorSieNoticeConfirmed },
update,

View file

@ -38,13 +38,13 @@ const tickFormatter = new Intl.NumberFormat('en-US', {
const Dashboard = () => {
const [date, setDate] = useState<string>(format(Date.now(), 'yyyy-MM-dd'));
const { data: totalData, error: totalError } = useSWR<TotalUsersResponse, RequestError>(
'/api/dashboard/users/total'
'api/dashboard/users/total'
);
const { data: newData, error: newError } = useSWR<NewUsersResponse, RequestError>(
'/api/dashboard/users/new'
'api/dashboard/users/new'
);
const { data: activeData, error: activeError } = useSWR<ActiveUsersResponse, RequestError>(
`/api/dashboard/users/active?date=${date}`
`api/dashboard/users/active?date=${date}`
);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });

View file

@ -40,7 +40,7 @@ const useGetStartedMetadata = () => {
const theme = useTheme();
const isLightMode = theme === AppearanceMode.LightMode;
const { data: demoApp, error } = useSWR<Application, RequestError>(
`/api/applications/${demoAppApplicationId}`,
`api/applications/${demoAppApplicationId}`,
{
shouldRetryOnError: (error: unknown) => {
if (error instanceof RequestError) {

View file

@ -32,7 +32,7 @@ const AssignPermissionsModal = ({ roleId, onClose }: Props) => {
setIsSubmitting(true);
try {
await api.post(`/api/roles/${roleId}/scopes`, {
await api.post(`api/roles/${roleId}/scopes`, {
json: { scopeIds: scopes.map(({ id }) => id) },
});
toast.success(t('role_details.permission.permission_assigned'));

View file

@ -33,7 +33,7 @@ const RolePermissions = () => {
const { data, error, mutate } = useSWR<[ScopeResponse[], number], RequestError>(
roleId &&
buildUrl(`/api/roles/${roleId}/scopes`, {
buildUrl(`api/roles/${roleId}/scopes`, {
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),
@ -57,7 +57,7 @@ const RolePermissions = () => {
setIsDeleting(true);
try {
await api.delete(`/api/roles/${roleId}/scopes/${scopeToBeDeleted.id}`);
await api.delete(`api/roles/${roleId}/scopes/${scopeToBeDeleted.id}`);
toast.success(
t('role_details.permission.permission_deleted', { name: scopeToBeDeleted.name })
);

View file

@ -32,7 +32,7 @@ const RoleSettings = () => {
return;
}
const updatedRole = await api.patch(`/api/roles/${role.id}`, { json: formData }).json<Role>();
const updatedRole = await api.patch(`api/roles/${role.id}`, { json: formData }).json<Role>();
reset(updatedRole);
onRoleUpdated(updatedRole);
toast.success(t('general.saved'));

View file

@ -32,7 +32,7 @@ const AssignUsersModal = ({ roleId, isRemindSkip = false, onClose }: Props) => {
setIsLoading(true);
try {
await api.post(`/api/roles/${roleId}/users`, {
await api.post(`api/roles/${roleId}/users`, {
json: { userIds: users.map(({ id }) => id) },
});
toast.success(t('role_details.users.users_assigned'));

View file

@ -44,7 +44,7 @@ const RoleUsers = () => {
const { data, error, mutate } = useSWR<[User[], number], RequestError>(
roleId &&
buildUrl(`/api/roles/${roleId}/users`, {
buildUrl(`api/roles/${roleId}/users`, {
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),
@ -68,7 +68,7 @@ const RoleUsers = () => {
setIsDeleting(true);
try {
await api.delete(`/api/roles/${roleId}/users/${userToBeDeleted.id}`);
await api.delete(`api/roles/${roleId}/users/${userToBeDeleted.id}`);
toast.success(t('role_details.users.deleted', { name: userToBeDeleted.name }));
await mutate();
setUserToBeDeleted(undefined);

View file

@ -33,7 +33,7 @@ const RoleDetails = () => {
const isPageHasTable =
pathname.endsWith(RoleDetailsTabs.Permissions) || pathname.endsWith(RoleDetailsTabs.Users);
const { data, error, mutate } = useSWR<Role, RequestError>(id && `/api/roles/${id}`);
const { data, error, mutate } = useSWR<Role, RequestError>(id && `api/roles/${id}`);
const { mutate: mutateGlobal } = useSWRConfig();
const isLoading = !data && !error;
@ -55,9 +55,9 @@ const RoleDetails = () => {
setIsDeleting(true);
try {
await api.delete(`/api/roles/${data.id}`);
await api.delete(`api/roles/${data.id}`);
toast.success(t('role_details.role_deleted', { name: data.name }));
await mutateGlobal('/api/roles');
await mutateGlobal('api/roles');
navigate('/roles', { replace: true });
} finally {
setIsDeleting(false);

View file

@ -44,7 +44,7 @@ const CreateRoleForm = ({ onClose }: Props) => {
scopeIds: conditional(scopes.length > 0 && scopes.map(({ id }) => id)),
};
const createdRole = await api.post('/api/roles', { json: payload }).json<Role>();
const createdRole = await api.post('api/roles', { json: payload }).json<Role>();
onClose(createdRole);
});

View file

@ -37,7 +37,7 @@ const Roles = () => {
keyword: '',
});
const url = buildUrl('/api/roles', {
const url = buildUrl('api/roles', {
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),

View file

@ -38,7 +38,7 @@ const ChangePassword = () => {
}
setIsLoading(true);
await api.patch(`/api/users/${userId}/password`, { json: { password } }).json();
await api.patch(`api/users/${userId}/password`, { json: { password } }).json();
setIsLoading(false);
setIsOpen(false);
toast.success(t('settings.password_changed'));

View file

@ -27,7 +27,7 @@ const Preview = ({ signInExperience, className }: Props) => {
const [language, setLanguage] = useState<LanguageTag>('en');
const [mode, setMode] = useState<AppearanceMode>(AppearanceMode.LightMode);
const [platform, setPlatform] = useState<'desktopWeb' | 'mobile' | 'mobileWeb'>('desktopWeb');
const { data: allConnectors } = useSWR<ConnectorResponse[], RequestError>('/api/connectors');
const { data: allConnectors } = useSWR<ConnectorResponse[], RequestError>('api/connectors');
const previewRef = useRef<HTMLIFrameElement>(null);
const { customPhrases } = useUiLanguages();

View file

@ -32,7 +32,7 @@ type Props = {
};
const GuideModal = ({ isOpen, onClose }: Props) => {
const { data } = useSWR<SignInExperience>('/api/sign-in-exp');
const { data } = useSWR<SignInExperience>('api/sign-in-exp');
const { data: preferences, update: updatePreferences } = useUserPreferences();
const { updateConfigs } = useConfigs();
const methods = useForm<SignInExperienceForm>();
@ -65,7 +65,7 @@ const GuideModal = ({ isOpen, onClose }: Props) => {
}
await Promise.all([
api.patch('/api/sign-in-exp', {
api.patch('api/sign-in-exp', {
json: signInExperienceParser.toRemoteModel(formData),
}),
updateConfigs({ signInExperienceCustomized: true }),

View file

@ -39,7 +39,7 @@ import {
const SignInExperience = () => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { tab } = useParams();
const { data, error, mutate } = useSWR<SignInExperienceType, RequestError>('/api/sign-in-exp');
const { data, error, mutate } = useSWR<SignInExperienceType, RequestError>('api/sign-in-exp');
const { configs, error: configsError, updateConfigs, mutate: mutateConfigs } = useConfigs();
const { error: languageError, isLoading: isLoadingLanguages } = useUiLanguages();
const [dataToCompare, setDataToCompare] = useState<SignInExperienceType>();
@ -73,7 +73,7 @@ const SignInExperience = () => {
const saveData = async () => {
const updatedData = await api
.patch('/api/sign-in-exp', {
.patch('api/sign-in-exp', {
json: signInExperienceParser.toRemoteModel(getValues()),
})
.json<SignInExperienceType>();

View file

@ -22,7 +22,7 @@ type Props = {
const LanguagesForm = ({ isManageLanguageVisible = false }: Props) => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data: signInExperience } = useSWR<SignInExperience, RequestError>('/api/sign-in-exp');
const { data: signInExperience } = useSWR<SignInExperience, RequestError>('api/sign-in-exp');
const { watch, control, register, setValue } = useFormContext<SignInExperienceForm>();
const isAutoDetect = watch('languageInfo.autoDetect');
const selectedDefaultLanguage = watch('languageInfo.fallbackLanguage');

View file

@ -35,7 +35,7 @@ const emptyUiTranslation = createEmptyUiTranslation();
const LanguageDetails = () => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data: signInExperience } = useSWR<SignInExperience, RequestError>('/api/sign-in-exp');
const { data: signInExperience } = useSWR<SignInExperience, RequestError>('api/sign-in-exp');
const { languages } = useUiLanguages();
@ -53,7 +53,7 @@ const LanguageDetails = () => {
);
const { data: customPhrase, mutate } = useSWR<CustomPhraseResponse, RequestError>(
`/api/custom-phrases/${selectedLanguage}`,
`api/custom-phrases/${selectedLanguage}`,
{
shouldRetryOnError: (error: unknown) => {
if (error instanceof RequestError) {
@ -104,14 +104,14 @@ const LanguageDetails = () => {
const upsertCustomPhrase = useCallback(
async (languageTag: LanguageTag, translation: Translation) => {
const updatedCustomPhrase = await api
.put(`/api/custom-phrases/${languageTag}`, {
.put(`api/custom-phrases/${languageTag}`, {
json: {
...cleanDeep(translation),
},
})
.json<CustomPhraseResponse>();
void globalMutate('/api/custom-phrases');
void globalMutate('api/custom-phrases');
return updatedCustomPhrase;
},
@ -125,9 +125,9 @@ const LanguageDetails = () => {
return;
}
await api.delete(`/api/custom-phrases/${selectedLanguage}`);
await api.delete(`api/custom-phrases/${selectedLanguage}`);
await globalMutate('/api/custom-phrases');
await globalMutate('api/custom-phrases');
setSelectedLanguage(languages.find((languageTag) => languageTag !== selectedLanguage) ?? 'en');
}, [api, globalMutate, isDefaultLanguage, languages, selectedLanguage, setSelectedLanguage]);

View file

@ -34,7 +34,7 @@ const AssignRolesModal = ({ user, onClose }: Props) => {
setIsSubmitting(true);
try {
await api.post(`/api/users/${user.id}/roles`, {
await api.post(`api/users/${user.id}/roles`, {
json: { roleIds: roles.map(({ id }) => id) },
});
toast.success(t('user_details.roles.role_assigned'));

View file

@ -39,7 +39,7 @@ const UserRoles = () => {
});
const { data, error, mutate } = useSWR<[Role[], number], RequestError>(
buildUrl(`/api/users/${userId}/roles`, {
buildUrl(`api/users/${userId}/roles`, {
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),
@ -63,7 +63,7 @@ const UserRoles = () => {
setIsDeleting(true);
try {
await api.delete(`/api/users/${userId}/roles/${roleToBeDeleted.id}`);
await api.delete(`api/users/${userId}/roles/${roleToBeDeleted.id}`);
toast.success(t('user_details.roles.deleted', { name: roleToBeDeleted.name }));
await mutate();
setRoleToBeDeleted(undefined);

View file

@ -34,7 +34,7 @@ const ConnectorName = ({ name }: { name: DisplayConnector['name'] }) =>
const UserSocialIdentities = ({ userId, identities, onDelete }: Props) => {
const api = useApi();
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data, error, mutate } = useSWR<ConnectorResponse[], RequestError>('/api/connectors');
const { data, error, mutate } = useSWR<ConnectorResponse[], RequestError>('api/connectors');
const [deletingConnector, setDeletingConnector] = useState<DisplayConnector>();
const [isSubmitting, setIsSubmitting] = useState(false);
@ -56,7 +56,7 @@ const UserSocialIdentities = ({ userId, identities, onDelete }: Props) => {
setIsSubmitting(true);
try {
await api.delete(`/api/users/${userId}/identities/${target}`);
await api.delete(`api/users/${userId}/identities/${target}`);
onDelete?.(target);
} finally {
setIsSubmitting(false);

View file

@ -72,7 +72,7 @@ const UserSettings = () => {
customData: guardResult.data,
};
const updatedUser = await api.patch(`/api/users/${user.id}`, { json: payload }).json<User>();
const updatedUser = await api.patch(`api/users/${user.id}`, { json: payload }).json<User>();
reset(userDetailsParser.toLocalForm(updatedUser));
onUserUpdated(updatedUser);
toast.success(t('general.saved'));

View file

@ -21,7 +21,7 @@ const ResetPasswordForm = ({ onClose, userId }: Props) => {
const onSubmit = async () => {
const password = nanoid(8);
setIsLoading(true);
await api.patch(`/api/users/${userId}/password`, { json: { password } }).json<User>();
await api.patch(`api/users/${userId}/password`, { json: { password } }).json<User>();
setIsLoading(false);
onClose?.(password);
};

View file

@ -41,7 +41,7 @@ const UserDetails = () => {
const [isResetPasswordFormOpen, setIsResetPasswordFormOpen] = useState(false);
const [resetResult, setResetResult] = useState<string>();
const { data, error, mutate } = useSWR<User, RequestError>(id && `/api/users/${id}`);
const { data, error, mutate } = useSWR<User, RequestError>(id && `api/users/${id}`);
const isLoading = !data && !error;
const api = useApi();
const navigate = useNavigate();
@ -59,7 +59,7 @@ const UserDetails = () => {
setIsDeleting(true);
try {
await api.delete(`/api/users/${data.id}`);
await api.delete(`api/users/${data.id}`);
toast.success(t('user_details.deleted', { name: data.name }));
navigate('/users');
} finally {

View file

@ -51,7 +51,7 @@ const CreateForm = ({ onClose, onCreate }: Props) => {
const password = nanoid(8);
const createdUser = await api.post('/api/users', { json: { ...data, password } }).json<User>();
const createdUser = await api.post('api/users', { json: { ...data, password } }).json<User>();
setCreatedUserInfo({
user: createdUser,

View file

@ -38,7 +38,7 @@ const Users = () => {
keyword: '',
});
const url = buildUrl('/api/users', {
const url = buildUrl('api/users', {
hideAdminUser: String(true),
page: String(page),
page_size: String(pageSize),