feat: update frontend references from User to PartyUser for party user management module
This commit is contained in:
@@ -22,7 +22,7 @@ type UsersData = {
|
|||||||
|
|
||||||
// TODO: i want to refactor / tidy here
|
// TODO: i want to refactor / tidy here
|
||||||
export function useGetPartyUsers() {
|
export function useGetPartyUsers() {
|
||||||
const url = `http://localhost:7272/api/party-user/list`;
|
const url = endpoints.partyUser.list;
|
||||||
|
|
||||||
const { data, isLoading, error, isValidating } = useSWR<UsersData>(url, fetcher, swrOptions);
|
const { data, isLoading, error, isValidating } = useSWR<UsersData>(url, fetcher, swrOptions);
|
||||||
|
|
||||||
@@ -180,13 +180,12 @@ export async function deletePartyUser(partyUserId: string) {
|
|||||||
/**
|
/**
|
||||||
* Work in local
|
* Work in local
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mutate(
|
mutate(
|
||||||
endpoints.partyUser.list,
|
endpoints.partyUser.list,
|
||||||
(currentData: any) => {
|
(currentData: any) => {
|
||||||
const currentProducts: IPartyUserItem[] = currentData?.partyUsers;
|
const currentPartyUsers: IPartyUserItem[] = currentData?.partyUsers;
|
||||||
|
|
||||||
const partyUsers = currentProducts.filter((partyUser) => partyUser.id !== partyUserId);
|
const partyUsers = currentPartyUsers.filter((partyUser) => partyUser.id !== partyUserId);
|
||||||
|
|
||||||
return { ...currentData, partyUsers };
|
return { ...currentData, partyUsers };
|
||||||
},
|
},
|
||||||
|
@@ -56,7 +56,7 @@ type Props = {
|
|||||||
currentUser?: IPartyUserItem;
|
currentUser?: IPartyUserItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function UserNewEditForm({ currentUser }: Props) {
|
export function PartyUserNewEditForm({ currentUser }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -103,8 +103,8 @@ export function UserNewEditForm({ currentUser }: Props) {
|
|||||||
try {
|
try {
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
await deletePartyUser(currentUser.id);
|
await deletePartyUser(currentUser.id);
|
||||||
toast.success(t('user deleted'));
|
toast.success(t('party user deleted'));
|
||||||
router.push(paths.dashboard.user.list);
|
router.push(paths.dashboard.partyUser.list);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -133,7 +133,7 @@ export function UserNewEditForm({ currentUser }: Props) {
|
|||||||
|
|
||||||
toast.success(currentUser ? t('Update success!') : t('Create success!'));
|
toast.success(currentUser ? t('Update success!') : t('Create success!'));
|
||||||
|
|
||||||
router.push(paths.dashboard.user.list);
|
router.push(paths.dashboard.partyUser.list);
|
||||||
|
|
||||||
// console.info('DATA', data);
|
// console.info('DATA', data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@@ -2,7 +2,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
|
import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
|
||||||
import { DashboardContent } from 'src/layouts/dashboard';
|
import { DashboardContent } from 'src/layouts/dashboard';
|
||||||
import { paths } from 'src/routes/paths';
|
import { paths } from 'src/routes/paths';
|
||||||
import { UserNewEditForm } from '../party-user-new-edit-form';
|
import { PartyUserNewEditForm } from '../party-user-new-edit-form';
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ export function UserCreateView() {
|
|||||||
sx={{ mb: { xs: 3, md: 5 } }}
|
sx={{ mb: { xs: 3, md: 5 } }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<UserNewEditForm />
|
<PartyUserNewEditForm />
|
||||||
</DashboardContent>
|
</DashboardContent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ import { CustomBreadcrumbs } from 'src/components/custom-breadcrumbs';
|
|||||||
import { DashboardContent } from 'src/layouts/dashboard';
|
import { DashboardContent } from 'src/layouts/dashboard';
|
||||||
import { paths } from 'src/routes/paths';
|
import { paths } from 'src/routes/paths';
|
||||||
import type { IPartyUserItem } from 'src/types/party-user';
|
import type { IPartyUserItem } from 'src/types/party-user';
|
||||||
import { UserNewEditForm } from '../party-user-new-edit-form';
|
import { PartyUserNewEditForm } from '../party-user-new-edit-form';
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -18,16 +18,16 @@ export function PartyUserEditView({ user: currentUser }: Props) {
|
|||||||
<DashboardContent>
|
<DashboardContent>
|
||||||
<CustomBreadcrumbs
|
<CustomBreadcrumbs
|
||||||
heading="Edit"
|
heading="Edit"
|
||||||
backHref={paths.dashboard.user.list}
|
backHref={paths.dashboard.partyUser.list}
|
||||||
links={[
|
links={[
|
||||||
{ name: t('Dashboard'), href: paths.dashboard.root },
|
{ name: t('Dashboard'), href: paths.dashboard.root },
|
||||||
{ name: t('User'), href: paths.dashboard.user.root },
|
{ name: t('Party User'), href: paths.dashboard.partyUser.root },
|
||||||
{ name: currentUser?.name },
|
{ name: currentUser?.name },
|
||||||
]}
|
]}
|
||||||
sx={{ mb: { xs: 3, md: 5 } }}
|
sx={{ mb: { xs: 3, md: 5 } }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<UserNewEditForm currentUser={currentUser} />
|
<PartyUserNewEditForm currentUser={currentUser} />
|
||||||
</DashboardContent>
|
</DashboardContent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user