1d78b2b65d
This commit introduces the functionality for super admins to change the status of other admin users to either 'Active' or 'Inactive'. This provides better control over admin account access. Key changes include: - A 'Status' column with a visual badge has been added to the admins table. - A new 'Change Status' action button, using a new `UserSettingIcon`, opens a modal for status updates. - The backend service and frontend mutation for updating an admin's status are implemented. - The `IUser` type and a new `AdminStatus` enum have been added to support this feature. Additionally, the confirmation modal implementation has been simplified across the admin and customer tables by removing the `modalConfig` state.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { Select } from "@/components/FormElements/select";
|
|
import { AdminStatus } from "@/constants/enums";
|
|
import { FormErrorMessages } from "@/constants/Texts";
|
|
import { TChangeAdminStatusCredentials } from "@/lib/api";
|
|
import { capitalize } from "@/utils/shared";
|
|
import { Dispatch, FC, SetStateAction } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
interface IProps {
|
|
status: AdminStatus;
|
|
setStatus: Dispatch<SetStateAction<string>>;
|
|
}
|
|
const ChangeStatusModalContent: FC<IProps> = ({ status, setStatus }) => {
|
|
const { register } = useForm<TChangeAdminStatusCredentials>({
|
|
mode: "onChange",
|
|
defaultValues: { status },
|
|
});
|
|
const adminStatusEntries = Object.entries(AdminStatus).map(
|
|
([key, value]) => ({
|
|
label: capitalize(key),
|
|
value,
|
|
}),
|
|
);
|
|
|
|
return (
|
|
<form>
|
|
<Select
|
|
{...register("status", {
|
|
required: { value: true, message: FormErrorMessages.required },
|
|
onChange(event) {
|
|
setStatus(event.target.value);
|
|
},
|
|
})}
|
|
items={adminStatusEntries}
|
|
label="Status"
|
|
name="status"
|
|
defaultValue={status}
|
|
placeholder="Please select new Status"
|
|
/>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
export default ChangeStatusModalContent;
|