All files / src/utils/components/profile OrganizationSettingsFields.jsx

9.09% Statements 1/11
0% Branches 0/23
0% Functions 0/1
9.09% Lines 1/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                        2x                                                                                                                    
import { Box, Divider, Typography } from "@mui/material";
import useOrganization from "@/utils/hooks/useOrganization";
import {
    formatDistrictAddress,
    formatProfilePlanLabel,
    formatSchoolAddress,
    formatSchoolLocation,
    getOrganizationDistrictName,
    getOrganizationPlanLabel,
    getOrganizationSchoolName,
} from "@/utils/helpers/organizationDisplay";
 
const OrganizationSettingsFields = ({ userData, userType }) => {
    const { organization, loading } = useOrganization(userType);
 
    const schoolName = getOrganizationSchoolName(organization, userData);
    const districtName = getOrganizationDistrictName(organization);
    const planLabel = formatProfilePlanLabel(getOrganizationPlanLabel(organization));
    const schoolLocation = formatSchoolLocation(organization?.school);
    const schoolAddress = formatSchoolAddress(organization?.school);
    const schoolSecondary = schoolLocation || schoolAddress || null;
    const districtSecondary = formatDistrictAddress(organization?.district);
 
    const settingsPrefix = userType === "student" ? "student-settings" : "teacher-settings";
 
    return (
        <>
            <div id={`${settingsPrefix}-organization-school`} className="settings-item">
                <div className="item-content">
                    <Typography color="text.secondary">School:</Typography>
                    <Typography color="text.primary">{loading && !organization ? "Loading…" : schoolName}</Typography>
                    {schoolSecondary ? (
                        <Typography variant="caption" color="text.secondary">
                            {schoolSecondary}
                        </Typography>
                    ) : null}
                    {schoolAddress && schoolAddress !== schoolSecondary ? (
                        <Typography variant="caption" color="text.secondary" display="block">
                            {schoolAddress}
                        </Typography>
                    ) : null}
                </div>
                <div className="item-actions"></div>
            </div>
            <Divider />
            <div id={`${settingsPrefix}-organization-district`} className="settings-item">
                <div className="item-content">
                    <Typography color="text.secondary">District:</Typography>
                    <Typography color="text.primary">{loading && !organization ? "Loading…" : districtName}</Typography>
                    {planLabel ? (
                        <Box id={`${settingsPrefix}-organization-plan-label`} sx={{ mt: 0.25 }}>
                            <Typography variant="caption" color="text.secondary">
                                {planLabel}
                            </Typography>
                        </Box>
                    ) : null}
                    {districtSecondary ? (
                        <Typography variant="caption" color="text.secondary" display="block">
                            {districtSecondary}
                        </Typography>
                    ) : null}
                </div>
                <div className="item-actions"></div>
            </div>
            <Divider />
        </>
    );
};
 
export default OrganizationSettingsFields;