bug fixed

This commit is contained in:
Malini 2025-12-17 11:20:12 +05:30
parent d14fb99d13
commit cdc14fe7e2
2 changed files with 55 additions and 5 deletions

View File

@ -12,7 +12,8 @@ import {
deleteEstablishment, deleteEstablishment,
uploadCompanyProfileCSV, uploadCompanyProfileCSV,
uploadCompanyProfileCSVAlternative, uploadCompanyProfileCSVAlternative,
downloadSampleFile downloadSampleFile,
sendWelcomeEmail
} from '@/services/establishments/establishmentService'; } from '@/services/establishments/establishmentService';
import { fetchProducts } from '@/services/masters/masterService'; import { fetchProducts } from '@/services/masters/masterService';
@ -30,6 +31,7 @@ const deleteIconSrc = '/assets/images/delete.svg';
const activeToggleSrc = '/assets/images/Toggle.svg'; const activeToggleSrc = '/assets/images/Toggle.svg';
const inactiveToggleSrc = '/assets/images/Toggle-inactive.svg'; const inactiveToggleSrc = '/assets/images/Toggle-inactive.svg';
const uploadImportIconSrc = '/assets/images/UploadSimple.svg'; const uploadImportIconSrc = '/assets/images/UploadSimple.svg';
const mailIconSrc = '/assets/images/material-symbols_mail-outline.svg';
// Custom Toast Component // Custom Toast Component
const CustomToast = ({ message, type, onClose }) => { const CustomToast = ({ message, type, onClose }) => {
@ -463,6 +465,7 @@ const validateCSVFile = (file, existingEstablishments = []) => {
}; };
const CompanyProfile = () => { const CompanyProfile = () => {
const [isSendingEmail, setIsSendingEmail] = React.useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
const [profiles, setProfiles] = React.useState([]); const [profiles, setProfiles] = React.useState([]);
const [isLoading, setIsLoading] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false);
@ -1581,6 +1584,25 @@ const CompanyProfile = () => {
setActiveStep((prev) => Math.min(prev + 1, formSteps.length - 1)); setActiveStep((prev) => Math.min(prev + 1, formSteps.length - 1));
}, [activeStep, form.userProfilePassword, form.userProfileConfirmPassword, formSteps.length, validateStepFields, selectedProducts, showToast]); }, [activeStep, form.userProfilePassword, form.userProfileConfirmPassword, formSteps.length, validateStepFields, selectedProducts, showToast]);
const handleSendWelcomeEmail = async (establishmentId) => {
if (!establishmentId) {
showToast('error', 'Invalid establishment ID');
return;
}
try {
setIsSendingEmail(true);
const response = await sendWelcomeEmail(establishmentId);
showToast('success', response.message || 'Welcome email sent successfully');
} catch (error) {
console.error('Error sending welcome email:', error);
const errorMessage = error.response?.data?.message || 'Failed to send welcome email';
showToast('error', errorMessage);
} finally {
setIsSendingEmail(false);
}
};
const handleToggleStatus = async (establishmentId, currentStatus) => { const handleToggleStatus = async (establishmentId, currentStatus) => {
try { try {
const newStatus = !currentStatus; const newStatus = !currentStatus;
@ -1696,7 +1718,7 @@ const displayedRows = sortedProfiles.map((item) => {
<img <img
src={pencilActiveSrc} src={pencilActiveSrc}
alt="Edit" alt="Edit"
className="h-[24px] w-[24px]" className="h-[25px] w-[25px]"
/> />
</button> </button>
@ -1714,14 +1736,14 @@ const displayedRows = sortedProfiles.map((item) => {
<img <img
src={viewIconSrc} src={viewIconSrc}
alt="View" alt="View"
className="h-[24px] w-[24px]" className="h-[25px] w-[25px]"
/> />
</button> </button>
{/* Toggle Status */} {/* Toggle Status */}
<button <button
type="button" type="button"
className="h-[20px] w-[40px] grid place-items-center rounded hover:bg-gray-50 cursor-pointer" className="h-[24px] w-[24px] grid place-items-center rounded hover:bg-gray-50 cursor-pointer ml-1"
title={item.status === "Active" ? "Deactivate" : "Activate"} title={item.status === "Active" ? "Deactivate" : "Activate"}
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
@ -1738,7 +1760,26 @@ const displayedRows = sortedProfiles.map((item) => {
: inactiveToggleSrc : inactiveToggleSrc
} }
alt={item.status === "Active" ? "Active" : "Inactive"} alt={item.status === "Active" ? "Active" : "Inactive"}
className="h-[20px] w-[40px] object-contain" className="h-[25px] w-[25px] object-contain"
/>
</button>
{/* Mail */}
<button
type="button"
className="h-[24px] w-[24px] grid place-items-center rounded hover:bg-gray-50 cursor-pointer ml-1"
title="Resend Email"
aria-label="Resend Email"
disabled={isSendingEmail}
onClick={async (e) => {
e.stopPropagation();
await handleSendWelcomeEmail(item.apiId || item.establishmentId);
}}
>
<img
src={mailIconSrc}
alt="Resend Email"
className={`h-[25px] w-[25px] ${isSendingEmail ? 'opacity-50' : ''}`}
/> />
</button> </button>
</div> </div>
@ -1746,6 +1787,7 @@ const displayedRows = sortedProfiles.map((item) => {
]; ];
}); });
// ... (rest of the code remains the same)
React.useEffect(() => { React.useEffect(() => {
const handle = setTimeout(() => { const handle = setTimeout(() => {

View File

@ -164,6 +164,13 @@ export const downloadSampleFile = async (config = {}) => {
return response.data; return response.data;
}; };
export const sendWelcomeEmail = async (establishmentId, config = {}) => {
const response = await postRequest('/trigger-establishment-users-welcome-email', {
establishment_id: establishmentId
}, config);
return response.data;
};
export default { export default {
fetchEstablishments, fetchEstablishments,
fetchEstablishmentDashboard, fetchEstablishmentDashboard,
@ -176,4 +183,5 @@ export default {
bulkUpdateEstablishments, bulkUpdateEstablishments,
bulkDeleteEstablishments, bulkDeleteEstablishments,
downloadSampleFile, downloadSampleFile,
sendWelcomeEmail,
}; };