Skip to content

Commit

Permalink
Update Prettier configuration and fix code formatting
Browse files Browse the repository at this point in the history
Refactor NavBar component to improve readability
Update ForgetPassword component message rendering
Modify userController to hide sensitive information for students
Refactor CompanyForm component to improve code readability
Update password validation in validateUser utility
Refactor companyRoutes to improve code readability
  • Loading branch information
Sagargupta16 committed Jan 30, 2024
1 parent ece787c commit f05cf28
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 325 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"singleQuote": true,
"tabWidth": 2,
"useTabs": true,
"printWidth": 120,
"printWidth": 150,
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "always",
Expand Down
18 changes: 8 additions & 10 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will
remove the single build dependency from your project.
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build
dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right
into your project so you have full control over them. All of the commands except `eject` will still work, but they will
point to the copied scripts so you can tweak them. At this point you're on your own.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have
full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this
point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you
shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't
customize it when you are ready for it.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this
feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the
[Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

Expand Down
87 changes: 18 additions & 69 deletions client/src/components/AuthForms/AuthenticationForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ const AuthenticationForm = () => {
};

const handleSuccess = (isSignIn, res) => {
toast.success(
<ToastContent res={isSignIn ? 'Sign In successful' : 'Sign Up successful'} messages={res.data.messages} />,
{
autoClose: 4000,
closeOnClick: true,
pauseOnHover: true
}
);
toast.success(<ToastContent res={isSignIn ? 'Sign In successful' : 'Sign Up successful'} messages={res.data.messages} />, {
autoClose: 4000,
closeOnClick: true,
pauseOnHover: true
});
if (isSignIn) {
localStorage.setItem('token', res.data.data.token);
navigate('/');
Expand All @@ -75,14 +72,11 @@ const AuthenticationForm = () => {
};

const handleError = (isSignIn, err) => {
toast.error(
<ToastContent res={isSignIn ? 'Sign In failed' : 'Sign Up failed'} messages={err.response.data.errors} />,
{
autoClose: 4000,
closeOnClick: true,
pauseOnHover: true
}
);
toast.error(<ToastContent res={isSignIn ? 'Sign In failed' : 'Sign Up failed'} messages={err.response.data.errors} />, {
autoClose: 4000,
closeOnClick: true,
pauseOnHover: true
});
};

const handleEmailChange = (e) => {
Expand Down Expand Up @@ -115,24 +109,14 @@ const AuthenticationForm = () => {
<div className={classes['auth-form__item']}>
<label htmlFor="email">Email</label>
<div className={classes['email-input-container']}>
<input
type="text"
placeholder="Enter your email"
onChange={handleEmailChange}
value={email.trim().replace('@student.nitw.ac.in', '')}
/>
<input type="text" placeholder="Enter your email" onChange={handleEmailChange} value={email.trim().replace('@student.nitw.ac.in', '')} />
<span className={classes['email-domain']}>@student.nitw.ac.in</span>
</div>
</div>
<div className={classes['auth-form__item']}>
<label htmlFor="password">Password</label>
<div className={classes['password-input-container']}>
<input
type={showPassword ? 'text' : 'password'}
placeholder="Password"
onChange={(e) => setPassword(e.target.value)}
value={password}
/>
<input type={showPassword ? 'text' : 'password'} placeholder="Password" onChange={(e) => setPassword(e.target.value)} value={password} />
<button type="button" className={classes['password-toggle']} onClick={toggleShowPassword}>
{showPassword ? <FaEyeSlash /> : <FaEye />}
</button>
Expand Down Expand Up @@ -198,40 +182,16 @@ const AuthenticationForm = () => {
}}
step="0.01"
/>
<input
type="text"
placeholder="PG Percentage"
value={pgPercentage}
onChange={(e) => setPgPercentage(e.target.value)}
disabled
/>
<input type="text" placeholder="PG Percentage" value={pgPercentage} onChange={(e) => setPgPercentage(e.target.value)} disabled />
</div>
<div className={classes['auth-form__item']}>
<label htmlFor="ug">UG</label>
<input
type="text"
placeholder="UG CGPA"
onChange={(e) => setUgCgpa(e.target.value)}
value={ugCgpa}
step="0.01"
/>
<input
type="text"
placeholder="UG Percentage"
onChange={(e) => setUgPercentage(e.target.value)}
value={ugPercentage}
step="0.01"
/>
<input type="text" placeholder="UG CGPA" onChange={(e) => setUgCgpa(e.target.value)} value={ugCgpa} step="0.01" />
<input type="text" placeholder="UG Percentage" onChange={(e) => setUgPercentage(e.target.value)} value={ugPercentage} step="0.01" />
</div>
<div className={classes['auth-form__item']}>
<label htmlFor="hsc">12th</label>
<input
type="text"
placeholder="HSC CGPA"
onChange={(e) => setHscCgpa(e.target.value)}
value={hscCgpa}
step="0.01"
/>
<input type="text" placeholder="HSC CGPA" onChange={(e) => setHscCgpa(e.target.value)} value={hscCgpa} step="0.01" />
<input
type="text"
placeholder="HSC Percentage"
Expand All @@ -242,13 +202,7 @@ const AuthenticationForm = () => {
</div>
<div className={classes['auth-form__item']}>
<label htmlFor="ssc">10th</label>
<input
type="text"
placeholder="SSC CGPA"
onChange={(e) => setSscCgpa(e.target.value)}
value={sscCgpa}
step="0.01"
/>
<input type="text" placeholder="SSC CGPA" onChange={(e) => setSscCgpa(e.target.value)} value={sscCgpa} step="0.01" />
<input
type="text"
placeholder="SSC Percentage"
Expand All @@ -266,12 +220,7 @@ const AuthenticationForm = () => {
onChange={(e) => setTotalGapInAcademics(e.target.value)}
/>
<label htmlFor="backlogs">Backlogs</label>
<input
type="number"
placeholder="Backlogs"
value={backlogs}
onChange={(e) => setBacklogs(e.target.value)}
/>
<input type="number" placeholder="Backlogs" value={backlogs} onChange={(e) => setBacklogs(e.target.value)} />
</div>

<div className={classes['auth-form__item_btn']}>
Expand Down
8 changes: 1 addition & 7 deletions client/src/components/AuthForms/ForgetPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ const ForgetPassword = ({ isFormOpen, onCloseAction }) => {
onCloseAction();
}}
onConfirm={() => onConfirmAction()}
message={
counter === 0
? 'Enter your College Email ID!!'
: counter === 1
? 'Check your email for OTP'
: 'Enter your new password'
}
message={counter === 0 ? 'Enter your College Email ID!!' : counter === 1 ? 'Check your email for OTP' : 'Enter your new password'}
buttonTitle={counter === 0 ? 'Send Email' : counter === 1 ? 'Verify OTP' : 'Reset Password'}
HasInput={() => (
<div className={classes['modal__input-container']}>
Expand Down
12 changes: 2 additions & 10 deletions client/src/components/Company/CompanyForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ const CompanyForm = ({ actionFunc, handleFormClose, initialData, isAdd }) => {
};
try {
const res = isAdd ? await actionFunc(newCompany) : await actionFunc(initialData._id, newCompany);
if (res.status === 200)
toast.success(
<ToastContent res="Success" messages={[`Company ${isAdd ? 'added' : 'updated'} successfully`]} />
);
if (res.status === 200) toast.success(<ToastContent res="Success" messages={[`Company ${isAdd ? 'added' : 'updated'} successfully`]} />);
else toast.error(<ToastContent res="Error" messages={res.data.errors} />);
handleFormClose(true);
} catch (error) {
Expand All @@ -122,12 +119,7 @@ const CompanyForm = ({ actionFunc, handleFormClose, initialData, isAdd }) => {

<div className="form-group">
<label htmlFor="status">Status</label>
<select
id="status"
className="form-select"
value={formData.status}
onChange={(e) => handleChange('status', e.target.value)}
>
<select id="status" className="form-select" value={formData.status} onChange={(e) => handleChange('status', e.target.value)}>
<option value="" disabled>
Select Status
</option>
Expand Down
83 changes: 29 additions & 54 deletions client/src/components/Company/CompanyTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CompanyTable = () => {
const [companyData, setCompanyData] = useState(null);
const [isFormOpen, setIsFormOpen] = useState(false);
const [isAdd, setIsAdd] = useState(false);
const userRole = getUser().role;
const user = getUser();
const [isModalOpen, setIsModalOpen] = useState(false);
const [companyToDelete, setCompanyToDelete] = useState(null);
const closeModal = () => setIsModalOpen(false);
Expand All @@ -37,9 +37,7 @@ const CompanyTable = () => {
const onConfirmDelete = async () => {
try {
await deleteCompany(companyToDelete.id);
toast.success(
<ToastContent res="success" messages={[`Company ${companyToDelete.name} deleted successfully.`]} />
);
toast.success(<ToastContent res="success" messages={[`Company ${companyToDelete.name} deleted successfully.`]} />);
setIsModalOpen(false);
fetchData();
} catch (error) {
Expand All @@ -54,27 +52,21 @@ const CompanyTable = () => {
setIsFormOpen(true);
};

const generateColumn = (field, headerName, width, sortable = true, resizable = true) => ({
const generateColumn = (field, headerName, width, pinned = null, sortable = true, resizable = true, cellRenderer = null) => ({
field,
headerName,
width,
pinned,
sortable,
resizable
resizable,
cellRenderer
});

const generateNestedColumn = (headerName, children) => ({
headerName,
children
});

const generateDateColumn = (field, headerName, width, sortable = true, resizable = true) => ({
...generateColumn(field, headerName, width, sortable, resizable),
valueFormatter: (params) =>
params.value
? new Date(params.value).toLocaleDateString('en-US', { day: 'numeric', month: 'short', year: 'numeric' })
: ''
});

const formatCutoff = (cutoff) => (cutoff.cgpa ? `${cutoff.cgpa} CGPA` : `${cutoff.percentage}%`);

const deleteButtonRenderer = (params) => {
Expand All @@ -93,49 +85,35 @@ const CompanyTable = () => {
);
};

const actionColumn = (actionName, actionButtonRenderer) => {
return {
...generateColumn(null, actionName, 55, false, false),
pinned: 'left',
cellRenderer: actionButtonRenderer,
initialHide: userRole !== 'admin' && userRole !== 'placementCoordinator'
};
};
const actionsColumn = generateNestedColumn('Actions', [
generateColumn(null, 'Delete', 55, 'left', false, false, deleteButtonRenderer),
generateColumn(null, 'Edit', 55, 'left', false, false, editButtonRenderer)
]);

const columnDefinitions = [
generateNestedColumn('Actions', [
actionColumn('Del', deleteButtonRenderer),
actionColumn('Edit', editButtonRenderer)
]),
{
...generateColumn('name', 'Name', 150),
pinned: 'left'
},
generateColumn('status', 'Status', 100, false),
...(user.role === 'admin' || user.role === 'placementCoordinator' ? [actionsColumn] : []),
generateColumn('name', 'Name', 150, 'left'),
generateColumn('status', 'Status', 100, null, false),
generateColumn('typeOfOffer', 'Offer', 90),
generateColumn('profile', 'Profile', 150),
generateColumn('profileCategory', 'Category', 100),
generateColumn('interviewShortlist', 'Shortlists', 120),
generateColumn('selectedStudents', 'Selects', 100),
generateDateColumn('dateOfOffer', 'Offer Date', 125),
generateColumn('dateOfOffer', 'Offer Date', 125, null, true, false, (params) =>
params.value ? new Date(params.value).toLocaleDateString('en-US', { day: 'numeric', month: 'short', year: 'numeric' }) : ''
),
generateColumn('locations', 'Locations', 130),
generateNestedColumn('CTC (LPA)', [
{
...generateColumn('ctc', 'CTC', 80, true, false),
valueFormatter: (params) => params.value.toFixed(2)
},
{
...generateColumn('ctcBase', 'Base', 80, true, false),
valueFormatter: (params) => params.value.toFixed(2)
}
generateColumn('ctc', 'CTC', 80, null, true, false, (params) => params.value.toFixed(2)),
generateColumn('ctcBase', 'Base', 80, null, true, false, (params) => params.value.toFixed(2))
]),
generateNestedColumn('Cutoffs', [
generateColumn('cutoff_pg', 'PG', 80, false, false),
generateColumn('cutoff_ug', 'UG', 80, false, false),
generateColumn('cutoff_12', '12', 80, false, false),
generateColumn('cutoff_10', '10', 80, false, false)
generateColumn('cutoff_pg', 'PG', 80, null, false, false),
generateColumn('cutoff_ug', 'UG', 80, null, false, false),
generateColumn('cutoff_12', '12', 80, null, false, false),
generateColumn('cutoff_10', '10', 80, null, false, false)
]),
generateColumn('bond', 'Bond', 60, false, false)
generateColumn('bond', 'Bond', 60, null, false, false)
];

const mapCompanyData = (company) => ({
Expand Down Expand Up @@ -165,21 +143,18 @@ const CompanyTable = () => {
const renderCompanyForm = () => {
if (!isFormOpen) return null;
return ReactDOM.createPortal(
<CompanyForm
actionFunc={isAdd ? addCompany : updateCompany}
initialData={companyData}
handleFormClose={handleCloseForm}
isAdd={isAdd}
/>,
<CompanyForm actionFunc={isAdd ? addCompany : updateCompany} initialData={companyData} handleFormClose={handleCloseForm} isAdd={isAdd} />,
document.getElementById('form-root')
);
};

return (
<>
<button className="btn btn-primary" onClick={handleAddCompanyClick}>
Add Company
</button>
{(user.role === 'admin' || user.role === 'placementCoordinator') && (
<button className="btn btn-primary" onClick={handleAddCompanyClick}>
Add Company
</button>
)}
{renderCompanyForm()}
<AgGridTable rowData={rowData} columnDefinitions={columnDefinitions} fetchData={fetchData} />
<Modal
Expand Down
7 changes: 1 addition & 6 deletions client/src/components/NavBar/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ const NavBar = () => {
</NavLink>
<div className={classes['nav__list']}>
{navItems.map((item) => (
<NavLink
to={item.to}
className={({ isActive }) => (isActive ? classes.active : undefined)}
aria-label={item.label}
key={item.to}
>
<NavLink to={item.to} className={({ isActive }) => (isActive ? classes.active : undefined)} aria-label={item.label} key={item.to}>
{item.icon}
</NavLink>
))}
Expand Down
Loading

0 comments on commit f05cf28

Please sign in to comment.