Skip to content

Commit

Permalink
TASK : #0000 If user is created from admin, that user will be shown f…
Browse files Browse the repository at this point in the history
…or update user profile for the first time login
  • Loading branch information
mahajanmahesh935 committed Aug 10, 2024
1 parent 86771b6 commit c6f7b93
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"react-modal": "^3.16.1",
"react-multi-carousel": "^2.8.5",
"react-scripts": "5.0.0",
"react-select": "^5.8.0",
"react-share": "^5.1.0",
"rxjs": "^7.8.1",
"styled-components": "^6.1.8",
Expand Down
33 changes: 32 additions & 1 deletion packages/nulp_elite/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import votingDashboard from "pages/voting/votingDashboard";
import pollsDetails from "pages/voting/pollsDetails";
const urlConfig = require("./configs/urlConfig.json");
const routeConfig = require("./configs/routeConfig.json");
import PopupForm from "pages/profileData"
import axios from 'axios';

function App() {
// const [t] = useTranslation();
Expand All @@ -64,6 +66,7 @@ function App() {
const [checkPref, setCheckPref] = React.useState(true);
const _userId = util.userId();
const [orgId, setOrgId] = useState();
const[userData,setUserData]=React.useState(false)

const routes = [
{
Expand Down Expand Up @@ -238,6 +241,27 @@ function App() {
console.error("Error fetching user data:", error);
}
};
const UserData=async()=>{
const url = `${urlConfig.URLS.POFILE_PAGE.USER_READ}`
const requestBody={
user_ids:[_userId]
}
const response=await axios.post(url,requestBody);
const Data=response.data;
console.log("Data of user----------- ",Data);
if(
Array.isArray(Data?.result) && Data.result.length === 0 ||
(Array.isArray(Data?.result) && Data.result.length > 0 &&
(
Data.result[0]?.designation === null ||
Data.result[0]?.user_type === null ||
Data.result[0]?.organisation === null
)
)
){
setUserData(true)
}
}
const fetchData = async () => {
try {
const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.USER.GET_PROFILE}${_userId}`;
Expand Down Expand Up @@ -278,6 +302,7 @@ function App() {
};

fetchData();
UserData();
}, []);

return (
Expand All @@ -287,12 +312,18 @@ function App() {
{/* <I18nextProvider i18n={i18n}> */}
{/* <ChakraProvider> */}
<React.Suspense>
{!checkPref && (
{!checkPref && !userData && (
<SelectPreference
isOpen={!checkPref}
onClose={() => setCheckPref(true)}
/>
)}
{userData && (<PopupForm
open={userData}
handleClose={()=> setUserData(false)}
></PopupForm>
)}


<Router>
<Routes>
Expand Down
5 changes: 5 additions & 0 deletions packages/nulp_elite/src/assets/userData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"designations": [ "Accountant", "Accountant & Cashier", "Accounts Clerk & Computer Operator", "Accounts Officer", "Additional City Engineer", "Additional Commissioner", "Additional Municipal Commissioner/ Additional Administrator", "Administrative Officer", "Advocate", "Analyst", "Architect", "Architect and Urban Designer", "Architect and Urban Planner", "Assessor", "Assistant Accounts Officer", "Assistant Architect", "Assistant Assessment", "Assistant Commissioner", "Assistant Engineer (Civil)", "Assistant Engineer (Electrical)", "Assistant Engineer (Mechanical)", "Assistant Engineer (Transport)", "Assistant Executive Engineer", "Assistant Law Officer", "Assistant Manager", "Assistant Municipal Commissioner", "Assistant Planner", "Assistant Professor", "Assistant Programmer", "Assistant Public Health Officer", "Assistant Public Information Officer", "Assistant Revenue Inspector", "Assistant Sanitary Inspector", "Assistant Tax Superintendent", "Assistant Town Planner", "Associate Manager", "Associate Town Planner", "Associate Vice President", "Auditor", "Billing Assistant", "Brand Ambassador", "Building Inspector", "C&D/ GIS operator", "Capacity Building Expert", "Chairperson", "Chief Accountant", "Chief Accounts Officer", "Chief Archives Officer", "Chief Auditor", "Chief Engineer/ Engineer-in-Chief", "Chief Enquiry Officer", "Chief Ethnographer", "Chief Executive Officer", "Chief Facilitator", "Chief Finance Officer", "Chief Fire Officer", "Chief Information Technology (IT) Officer", "Chief Labour Officer", "Chief Municipal Officer", "Chief Operating Officer", "Chief Personnel Officer", "Chief Sanitary Inspector", "Chief Security Officer", "Chief Town Planner", "City Coordinator", "City Data Officer", "City Engineer", "City Health Officer", "City Manager", "City Project Officer", "Civil Engineer", "Clerk", "Collector", "Commissioner", "Company Secretary", "Computer Operator", "Computer Programmer", "Consultant", "Councillor", "Customer Support Leader", "Data Analyst", "Data Entry Operator", "Deputy Administrator", "Deputy Director", "Deputy General Manager", "Deputy Municipal Commissioner", "Development Fellow", "Director", "Director Town Planning", "District Coordinator", "Divisional Coordinator", "Draughtsman", "Education Officer", "Engineer", "Environment officer - climate change", "Executive Engineer", "Executive Engineer (Civil)", "Executive Health Officer", "Executive Officer", "Executive Town Planner", "Fellow", "Finance Officer", "Garden Superintendent", "General Manager", "Geologist", "GIS Expert", "Head Clerk", "Head of Department", "Health Assistant", "Health Officer", "Heavy Vehicle Driver", "Horticulture Officer", "Human Resource Officer", "IEC Expert", "Information Technology (IT) Officer", "Joint City Engineer", "Joint Commissioner", "Junior Architect", "Junior Assistant", "Junior Engineer (Civil)", "Junior Engineer (Electrical)", "Junior Engineer (Mechanical)", "Junior Planner", "Law Assistant", "Law Officer", "Lead Architect", "Legal assistant", "Legal Officer", "Light Vehicle Driver", "Lower Divisional Clerk", "Manager", "Medical Officer", "Member Secretary", "Monitoring Evaluation Expert", "Municipal Architect", "Municipal Commissioner/ Administrator", "Municipal Secretary", "Office Assistant cum Accountant", "Office Assistant cum Comp Operator", "Peon", "Personal Assistant", "PG Student", "PHD Scholar", "Planning Assistant", "Professor", "Program Associate", "Program Fellow", "Programmer", "Project Coordinator", "Project Lead", "Public Health Officer", "Public Information Officer", "Public Relations Officer", "Publicity Assistant", "Revenue Inspector", "Sanitary & Food Inspector", "Sanitary Supervisor", "Sanitation Inspector", "Sanitation Worker/ Sweeper", "Secretary", "Section Officer/ Land Revenue Officer", "Security Officer", "Senior Assistant Urban Planner", "Senior Associate", "Senior Clerk", "Senior Consultant", "Senior Research Associate", "Software Developer", "Special Officer", "Stenographer", "Street Light Inspector", "Student", "Sub Engineer", "Superintendent Engineer", "Supervisor", "Surveyor/ Tracer", "Sweeper", "SWM Expert", "System Analyst", "Tax collector", "Tax Recovery Officer", "Team Lead", "Technical Advisor to Chief Engineer", "Technical Assistant", "Town Planner", "Transport Planner", "Undergraduate", "Upper Division Clerk", "Urban Designer", "Urban Development Expert", "Urban Planner", "Valuation Officer", "Veterinary Assistant", "Veterinary Officer", "Vice Chairman", "Vice President", "Vigilance Officer", "Ward Officer",
"Zonal and Taxation Officer","other"],
"userTypes": ["State Governments / Parastatal Bodies", "Urban Local Bodies / Special Purpose Vehicles", "Academia and Research Organisations", "Multilateral / Bilateral Agencies", "Industries"]
}
92 changes: 92 additions & 0 deletions packages/nulp_elite/src/pages/profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const Profile = () => {
bio: "",
designation: "",
otherDesignation: "",
userType: '',
otherUserType: '',
organisation:""
});
const [originalUserInfo, setOriginalUserInfo] = useState({});
const [isFormDirty, setIsFormDirty] = useState(false);
Expand All @@ -125,6 +128,8 @@ const Profile = () => {
const [showCertificate, setShowCertificate] = useState(false);
const [isButtonDisabled, setIsButtonDisabled] = useState(false);
const [orgId, setOrgId] = useState();
const userTypesList = ["State Governments / Parastatal Bodies", "Urban Local Bodies / Special Purpose Vehicles", "Academia and Research Organisations", "Multilateral / Bilateral Agencies", "Industries","Others"];


// for bar charts
const defaultCertData = {
Expand Down Expand Up @@ -280,13 +285,20 @@ const Profile = () => {
bio: userInfo[0]?.bio,
designation: userInfo[0]?.designation,
otherDesignation: "",
userType:userInfo[0].user_type,
otherUserType:"",
organisation:userInfo[0].organisation
});
setOriginalUserInfo({
firstName: userData?.result?.response.firstName,
lastName: userData?.result?.response.lastName,
bio: userInfo[0]?.bio,
designation: userInfo[0]?.designation,
otherDesignation: "",
userType:userInfo[0].user_type,
otherUserType:"",
organisation:userInfo[0].organisation

});
}
setDomain(userData?.result?.response.framework.board);
Expand Down Expand Up @@ -450,6 +462,10 @@ const Profile = () => {
: editedUserInfo.designation,
bio: editedUserInfo.bio,
created_by: _userId,
user_type:editedUserInfo.userType === "Other"
? editedUserInfo.otherUserType
: editedUserInfo.userType,
organisation:editedUserInfo.organisation
};
try {
const url = `${urlConfig.URLS.POFILE_PAGE.USER_UPDATE}?user_id=${_userId}`;
Expand Down Expand Up @@ -1010,7 +1026,83 @@ const Profile = () => {
}
/>
</Box>

)}
<Box py={1}>
<FormControl
fullWidth
style={{ marginTop: "10px" }}
>
<InputLabel
id="designation-label"
className="year-select"
>
{" "}
{t("userType")}{" "}
</InputLabel>
<Select
labelId="designation-label"
id="designation"
value={editedUserInfo.userType}
onChange={(e) =>
setEditedUserInfo({
...editedUserInfo,
userType: e.target.value,
})
}
>
{userTypesList.map((desig, index) => (
<MenuItem key={index} value={desig}>
{desig}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
{editedUserInfo.userType === "Others" && (
<Box py={1}>
<CssTextField
id="otherDesignation"
name="otherDesignation"
label={
<span>
{t("UserType")}{" "}
<span className="required">*</span>
</span>
}
variant="outlined"
size="small"
value={editedUserInfo.otherUserType}
onChange={(e) =>
setEditedUserInfo({
...editedUserInfo,
otherUserType: e.target.value,
})
}
/>
</Box>

)}
<Box py={2}>
<TextField
id="bio"
name="bio"
label={<span>{t("Organisation")}</span>}
multiline
rows={3}
variant="outlined"
fullWidth
value={editedUserInfo.organisation}
onChange={(e) =>
setEditedUserInfo({
...editedUserInfo,
organisation: e.target.value,
})
}
inputProps={{ maxLength: MAX_CHARS }}
/>
</Box>

<Box py={2}>
<TextField
id="bio"
Expand Down
136 changes: 136 additions & 0 deletions packages/nulp_elite/src/pages/profileData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import React, { useState, useEffect } from 'react';
import {
Dialog,
DialogContent,
DialogTitle,
TextField,
FormControl,
Button,
DialogActions,
} from '@mui/material';
import Select from 'react-select';
import axios from 'axios';
const userData = require('../assets/userData.json');
import * as util from '../services/utilService';
const urlConfig = require('../configs/urlConfig.json');

const PopupForm = ({ open, handleClose }) => {
const [organization, setOrganization] = useState('');
const [bio, setBio] = useState('');
const [designation, setDesignation] = useState('');
const [userType, setUserType] = useState('');
const [designations, setDesignations] = useState([]);
const [userTypes, setUserTypes] = useState([]);
const [customDesignation, setCustomDesignation] = useState('');
const [customUserType, setCustomUserType] = useState('');
const _userId = util.userId();

useEffect(() => {
setDesignations([
...userData.designations.map((type) => ({ value: type, label: type })),
{ value: 'other', label: 'Other' }
]);
setUserTypes([
...userData.userTypes.map((type) => ({ value: type, label: type })),
{ value: 'other', label: 'Other' }
]);
}, []);

const isSubmitDisabled = !organization || !designation || !userType || (designation === 'other' && !customDesignation) || (userType === 'other' && !customUserType);

const handleSubmit = async () => {
const finalDesignation = designation === 'other' ? customDesignation : designation;
const finalUserType = userType === 'other' ? customUserType : userType;

const requestData = {
organisation: organization,
designation: finalDesignation,
user_type: finalUserType,
bio: bio
};

try {
const url = `${urlConfig.URLS.POFILE_PAGE.USER_UPDATE}?user_id=${_userId}`;
const response = await axios.put(url, requestData);
console.log('API Response:', response.data);
} catch (error) {
console.error('API Error:', error);
}

handleClose();
};

return (
<Dialog open={open}>
<DialogTitle>User Information</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
label={<span>Organization <span style={{ color: 'red' }}>*</span></span>}
type="text"
fullWidth
value={organization}
onChange={(e) => setOrganization(e.target.value)}
/>
<TextField
margin="dense"
label="Bio"
type="text"
fullWidth
value={bio}
onChange={(e) => setBio(e.target.value)}
/>
<FormControl fullWidth margin="dense">
<Select
options={designations}
value={designations.find((option) => option.value === designation)}
onChange={(selectedOption) => setDesignation(selectedOption.value)}
placeholder="Select Designation"
isClearable
/>
{designation === 'other' && (
<TextField
margin="dense"
label="Enter Custom Designation"
type="text"
fullWidth
value={customDesignation}
onChange={(e) => setCustomDesignation(e.target.value)}
/>
)}
</FormControl>
<FormControl fullWidth margin="dense">
<Select
options={userTypes}
value={userTypes.find((option) => option.value === userType)}
onChange={(selectedOption) => setUserType(selectedOption.value)}
placeholder="Select User Type"
isClearable
/>
{userType === 'other' && (
<TextField
margin="dense"
label="Enter Custom User Type"
type="text"
fullWidth
value={customUserType}
onChange={(e) => setCustomUserType(e.target.value)}
/>
)}
</FormControl>
</DialogContent>
<DialogActions>
<Button
onClick={handleSubmit}
color="primary"
disabled={isSubmitDisabled}
>
Submit
</Button>
</DialogActions>
</Dialog>
);
};

export default PopupForm;
Loading

0 comments on commit c6f7b93

Please sign in to comment.