| @@ -66,7 +66,7 @@ export const editUser = async (id: number, data: UserInputs) => { | |||||
| }; | }; | ||||
| export const createUser = async (data: UserInputs) => { | export const createUser = async (data: UserInputs) => { | ||||
| const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/save`, { | |||||
| const newUser = await serverFetchWithNoContent(`${BASE_API_URL}/user/save`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| @@ -76,7 +76,7 @@ export const createUser = async (data: UserInputs) => { | |||||
| }; | }; | ||||
| export const deleteUser = async (id: number) => { | export const deleteUser = async (id: number) => { | ||||
| const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, { | |||||
| const newUser = await serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, { | |||||
| method: "DELETE", | method: "DELETE", | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| @@ -41,8 +41,12 @@ export async function serverFetchWithNoContent(...args: FetchParams) { | |||||
| case 401: | case 401: | ||||
| signOutUser(); | signOutUser(); | ||||
| default: | default: | ||||
| console.error(await response.text()); | |||||
| throw Error("Something went wrong fetching data in server."); | |||||
| const errorText = await response.text(); | |||||
| console.error(`Server error (${response.status}):`, errorText); | |||||
| throw new ServerFetchError( | |||||
| `Server error: ${response.status} ${response.statusText}. ${errorText || "Something went wrong fetching data in server."}`, | |||||
| response | |||||
| ); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -61,9 +61,11 @@ const UserSearch: React.FC<Props> = ({ users }) => { | |||||
| const onDeleteClick = useCallback((users: UserResult) => { | const onDeleteClick = useCallback((users: UserResult) => { | ||||
| deleteDialog(async () => { | deleteDialog(async () => { | ||||
| await deleteUser(users.id); | await deleteUser(users.id); | ||||
| setFilteredUser(prev => prev.filter(user => user.id !== users.id)); | |||||
| router.refresh(); | |||||
| successDialog(t("Delete Success"), t); | successDialog(t("Delete Success"), t); | ||||
| }, t); | }, t); | ||||
| }, [t]); | |||||
| }, [t, router]); | |||||
| const columns = useMemo<Column<UserResult>[]>( | const columns = useMemo<Column<UserResult>[]>( | ||||
| () => [ | () => [ | ||||