Skip to content

Commit

Permalink
Merge pull request #14 from AkshataKatwal16/admin
Browse files Browse the repository at this point in the history
Issue feat#PS-1082: fix issue in protected route
  • Loading branch information
itsvick authored Jul 8, 2024
2 parents ab42ecd + 2ad54f6 commit cc2dc30
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 23 deletions.
17 changes: 12 additions & 5 deletions src/components/ProtectedRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ import { useTranslation } from 'next-i18next';

const ProtectedRoute = ({ children }) => {
const { t } = useTranslation();

let user;
const router = useRouter();
const { user, loading } = useAuth();

const { loading } = useAuth();

console.log(user, loading)
useEffect(() => {
let user;
if (typeof window !== "undefined" && window.localStorage) {
user= localStorage.getItem('token');
}


if (!loading && !user) {
router.push('/login');
}
}, [user, loading, router]);
}, [ loading, router]);

if (loading || !user) {
if (loading) {
return <p>{t('COMMON.LOADING')}</p>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/cohorts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import ProtectedRoute from "../components/ProtectedRoute";
const Cohorts = () => {
const { t } = useTranslation();
return (
// <ProtectedRoute>
<ProtectedRoute>
<>
<h1>{t("SIDEBAR.COHORTS")}</h1>
</>
// </ProtectedRoute>
</ProtectedRoute>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/createPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const CreatePlan = () => {
const { t } = useTranslation();

return (
// <ProtectedRoute>
<ProtectedRoute>
<>
<h1>{t("SIDEBAR.CREATE_PLAN")}</h1>
</>
// </ProtectedRoute>
</ProtectedRoute>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import ProtectedRoute from '../components/ProtectedRoute';
const Dashboard = () => {
const { t } = useTranslation();
return (
// <ProtectedRoute>
<ProtectedRoute>
<>
<h1>{t("SIDEBAR.DASHBOARD")}</h1>
<p>Welcome to your dashboard</p>
</>

// </ProtectedRoute>
</ProtectedRoute>
);
};

Expand Down
42 changes: 41 additions & 1 deletion src/pages/faciliator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ type UserDetails = {
const AllStates = ["maharashtra", "Gujarat"];
const AllDistrict = ["Kolhapur", "Pune"];
const AllBlocks = ["Kothrud", "Warje"];
const Sort = ["Names", "A-Z" , "Z-A" ,"Centers"];


const Facilitators: React.FC = () => {
const [selectedState, setSelectedState] = useState("All states");
const [selectedDistrict, setSelectedDistrict] = useState("All Districts");
const [selectedBlock, setSelectedBlock] = useState("All Blocks");
const [selectedSort, setSelectedSort] = useState("Sort");

const { t } = useTranslation();
const [data, setData] = useState<UserDetails[]>([]);

Expand All @@ -48,6 +52,9 @@ const Facilitators: React.FC = () => {
const handleBlockChange = (event: SelectChangeEvent) => {
setSelectedBlock(event.target.value as string);
};
const handleSortChange = (event: SelectChangeEvent) => {
setSelectedSort(event.target.value as string);
};
console.log(data[0])
useEffect(() => {
const fetchUserList = async () => {
Expand Down Expand Up @@ -152,7 +159,40 @@ console.log(data[0])
<Typography>
{t("SIDEBAR.FACILITATORS")}
</Typography>
<SearchBar placeholder={t("NAVBAR.SEARCHBAR_PLACEHOLDER")} backgroundColor="#EEEEEE" />
<Box
sx={{
display: "flex",
flexDirection: "row",
gap: isMobile ? "0.1px" : "16px",
}}
>
<Box>
<SearchBar width="100%" placeholder={t("NAVBAR.SEARCHBAR_PLACEHOLDER")} backgroundColor="#EEEEEE" />

</Box>
<FormControl sx={{ m: "1rem 1 1rem" }}>
<Select
value={selectedSort}
onChange={handleSortChange}
displayEmpty
style={{
borderRadius: "0.5rem",
width: "117px",
height: "32px",
marginBottom: "0rem",
fontSize: "14px",
}}
>
<MenuItem value="Sort">Sort</MenuItem>
{Sort.map((state, index) => (
<MenuItem value={state} key={index}>
{state}
</MenuItem>
))}
</Select>
</FormControl>
</Box>

<Box
sx={{
display: "flex",
Expand Down
10 changes: 5 additions & 5 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const Home: React.FC = () => {
if (typeof window !== 'undefined' && window.localStorage) {
const token = localStorage.getItem('token');
setLoading(false);
// if (token) {
// push('/dashboard');
// } else {
push('/login', undefined, { locale: 'en' });
// }
if (token) {
push('/dashboard');
} else {
push('/login', undefined, { locale: 'en' });
}
}
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/learners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import ProtectedRoute from "../components/ProtectedRoute";
const Learners = () => {
const { t } = useTranslation();
return (
// <ProtectedRoute>
<ProtectedRoute>
<>
<h1>{t("SIDEBAR.LEARNERS")}</h1>
</>
// </ProtectedRoute>
</ProtectedRoute>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/teamLeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import ProtectedRoute from '../components/ProtectedRoute';
const TeamLeader = () => {
const { t } = useTranslation();
return (
// <ProtectedRoute>
<ProtectedRoute>
<>
<h1> {t("SIDEBAR.TEAM_LEADERS")}</h1>
</>

// </ProtectedRoute>
</ProtectedRoute>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/viewPlans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import ProtectedRoute from "../components/ProtectedRoute";
const ViewPlans = () => {
const { t } = useTranslation();
return (
// <ProtectedRoute>
<ProtectedRoute>
<>
<h1>{t("SIDEBAR.VIEW_PLANS")}</h1>
</>

// </ProtectedRoute>
</ProtectedRoute>
);
};

Expand Down

0 comments on commit cc2dc30

Please sign in to comment.