Added Admin ,Super Admin Super Admin User based on UserDropDown
This commit is contained in:
parent
28f3b12385
commit
d9df39eee1
|
|
@ -22,12 +22,14 @@ import { ApplicationPreferences } from '../../Features/BrachLogin/BranchLogin.js
|
|||
import './PreferenceList.scss';
|
||||
import { InputField } from '../../Components/Forms/InputField.jsx';
|
||||
import { changePreferenceData } from '../../Features/BookingScreen/BookingData/BookingData.js';
|
||||
import { DropDowns } from '../../Components/Forms/DropDown.jsx';
|
||||
import { getBranchUsers } from '../../Features/UserAccount/userData.js';
|
||||
import { UserDataBasedOnBranchId } from '../../Features/Reports/Reports.js';
|
||||
|
||||
const PreferenceList = ({ setting = false }) => {
|
||||
const { SadminuserAccess, featureaddDetails } = useAuth();
|
||||
const dispatch = useDispatch();
|
||||
const formRef = useRef();
|
||||
|
||||
const CompId = getSession('CompId');
|
||||
const BranchId = getSession('BranchId');
|
||||
const AppId = getSession('AppId');
|
||||
|
|
@ -42,8 +44,10 @@ const PreferenceList = ({ setting = false }) => {
|
|||
const [activeSection, setActiveSection] = useState('general');
|
||||
const [empData, setEmpData] = useState();
|
||||
const [preferenceConfigs, setPreferenceConfigs] = useState([]);
|
||||
const [selectedUserId, setSelectedUserId] = useState([]);
|
||||
|
||||
const [addnewAccess, setAddNewAccess] = useState(true);
|
||||
const [userDropDown, setUserDropDown] = useState();
|
||||
|
||||
const tableValue = useSelector(settingDataSelector);
|
||||
const appPreferences = useSelector(ApplicationPreferences);
|
||||
|
|
@ -73,6 +77,7 @@ const PreferenceList = ({ setting = false }) => {
|
|||
console.log(featureaddDetails, 'featureaddDetails');
|
||||
|
||||
const buildInitialValues = () => ({
|
||||
userId: selectedUserId,
|
||||
dashboard: allSettingsMap['dashboard']?.value === 'Y',
|
||||
shortcutkeys: allSettingsMap['shortcutkeys']?.value === 'Y',
|
||||
autoreceivestock: allSettingsMap['autoreceivestock']?.value === 'Y',
|
||||
|
|
@ -188,7 +193,7 @@ const PreferenceList = ({ setting = false }) => {
|
|||
],
|
||||
})
|
||||
);
|
||||
fetchTableData();
|
||||
userDropData()
|
||||
|
||||
const centerPageSub = document.querySelector('.centerPageSub');
|
||||
if (centerPageSub) {
|
||||
|
|
@ -201,6 +206,9 @@ const PreferenceList = ({ setting = false }) => {
|
|||
}
|
||||
};
|
||||
}, []);
|
||||
useEffect(()=>{
|
||||
fetchTableData();
|
||||
},[selectedUserId])
|
||||
|
||||
useEffect(() => {
|
||||
if (settingsList) {
|
||||
|
|
@ -302,7 +310,7 @@ const PreferenceList = ({ setting = false }) => {
|
|||
};
|
||||
|
||||
const fetchTableData = async () => {
|
||||
const res = await dispatch(gettableData({ CompId, BranchId, AppId })).unwrap();
|
||||
const res = await dispatch(gettableData({ CompId, BranchId, AppId,UserId:selectedUserId })).unwrap();
|
||||
if (res?.data?.statusCode === 1 && res?.data?.data?.length > 0) {
|
||||
await dispatch(changePreferenceData(res?.data?.data));
|
||||
} else {
|
||||
|
|
@ -342,7 +350,7 @@ const PreferenceList = ({ setting = false }) => {
|
|||
const handleSubmit = async () => {
|
||||
const values = formRef.current.getFieldsValue();
|
||||
const salesMode = values.salesmode;
|
||||
console.log('Sales Mode:', values.salesmode);
|
||||
console.log('Sales Mode:', values);
|
||||
console.log('Retail Short Name:', values.retailshortname);
|
||||
console.log('Wholesale Short Name:', values.wholesaleshortname);
|
||||
const settings = settingsList || [];
|
||||
|
|
@ -453,8 +461,9 @@ const PreferenceList = ({ setting = false }) => {
|
|||
BranchId,
|
||||
CreatedBy: UserId,
|
||||
AppId,
|
||||
userId: UserType === 'Employee' ? UserId : values.userId,
|
||||
SettingDtlDetails: updatedSettings,
|
||||
};
|
||||
};;
|
||||
const response = await dispatch(postPreferenceAppNames(payload)).unwrap();
|
||||
|
||||
if (response?.data?.statusCode === 1) {
|
||||
|
|
@ -467,6 +476,56 @@ const PreferenceList = ({ setting = false }) => {
|
|||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (userDropDown?.length > 0 && !formRef.current?.getFieldValue("userId")) {
|
||||
const adminUser = userDropDown.find(
|
||||
(user) => user.UserTypeName === "Admin"
|
||||
);
|
||||
|
||||
if (adminUser) {
|
||||
formRef.current?.setFieldsValue({
|
||||
userId: adminUser.UserId
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [userDropDown]);
|
||||
const UserDropDownChange = (value) => {
|
||||
let user = userDropDown?.find((item) => item?.UserId === value);
|
||||
setSelectedUserId(user?.UserId)
|
||||
formRef.current?.setFieldsValue({
|
||||
userId: value,
|
||||
});
|
||||
};
|
||||
const userDropData = async () => {
|
||||
const data ={
|
||||
branchId:BranchId,
|
||||
compId:CompId,
|
||||
appId:AppId
|
||||
}
|
||||
const gettinguserDropDown = await dispatch(getBranchUsers(data)).unwrap();
|
||||
// const gettinguserDropDown = await dispatch(UserDataBasedOnBranchId(BranchId)).unwrap();
|
||||
|
||||
|
||||
if (gettinguserDropDown?.data?.statusCode === 1) {
|
||||
const finaluserDropDown = gettinguserDropDown?.data?.data?.filter(
|
||||
(value) => value.ActiveStatus === "A"
|
||||
);
|
||||
|
||||
setUserDropDown(finaluserDropDown);
|
||||
|
||||
if (UserType === 'Employee') {
|
||||
setSelectedUserId(UserId);
|
||||
} else {
|
||||
const adminUser = finaluserDropDown.find(
|
||||
(user) => user.UserTypeName === "Admin"
|
||||
);
|
||||
if (adminUser) {
|
||||
setSelectedUserId(adminUser.UserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const renderCheckbox = (name, label) =>
|
||||
allSettingsMap[name] !== undefined && (
|
||||
<Form.Item name={name} label={label} valuePropName="checked">
|
||||
|
|
@ -561,6 +620,27 @@ const PreferenceList = ({ setting = false }) => {
|
|||
initialValues={initialValues}
|
||||
className="preferences-list"
|
||||
>
|
||||
{(UserType === 'Admin' || UserType === 'Super Admin' || UserType === 'Super Admin User')&& ( <span>
|
||||
<Form.Item
|
||||
name="userId"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: 'Please select a User',
|
||||
},
|
||||
]}
|
||||
>
|
||||
<DropDowns
|
||||
label={<label className="required">Users</label>}
|
||||
valueData={formRef.current?.getFieldValue("userId")}
|
||||
options={userDropDown?.map((option) => ({
|
||||
label: option?.UserName || option?.MobileNo,
|
||||
value: option?.UserId,
|
||||
}))}
|
||||
onChangeFunction={(value, option) => UserDropDownChange(value, option)}
|
||||
/>
|
||||
</Form.Item>
|
||||
</span>)}
|
||||
<div
|
||||
style={{
|
||||
backgroundColor:
|
||||
|
|
|
|||
Loading…
Reference in New Issue