Frontend
const { data, status } = await axios.post(
`${apiUrl}/users/${userId}/projects`,
{
name: name.trim(),
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${jwt}`,
},
},
);export const fetchAllUserTasks = createAsyncThunk(
"tasks/fetchAllUserTasks",
async (projectName: string, { getState, rejectWithValue }) => {
const { user, auth } = getState() as RootState;
const userId = user.userId;
const token = auth.token;
if (!userId || !token) {
return rejectWithValue("Please login first");
}
try {
const response = await axios.get(
`${apiUrl}/users/${userId}/projects/${projectName}/tasks`,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);
if (response.status !== 200) {
throw new Error("Something went wrong!");
}
return await response.data;
} catch (err) {
if (err instanceof Error) {
toast.error(err.message);
return rejectWithValue(err.message);
}
return rejectWithValue("Something went wrong!");
}
},
);Last updated