Skip to content

Commit

Permalink
Fix Sign in button
Browse files Browse the repository at this point in the history
Signed-off-by: Rafi <[email protected]>
  • Loading branch information
refoo0 committed Jul 18, 2024
1 parent f8fee68 commit 0a913ed
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/decorators/withOrganization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function withOrganization(ctx: GetServerSidePropsContext) {
const organization: OrganizationDetailsDTO = await r.json();

if (!r.ok) {
console.log("LOGIN REDIRECT");
console.log("LOGIN REDIRECT", r);
// it must be an 500
throw new HttpError({
redirect: {
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/withOrgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function withOrgs(ctx: GetServerSidePropsContext) {
const r = await devGuardApiClient("/organizations/");

if (!r.ok) {
console.log("LOGIN REDIRECT");
console.log("LOGIN REDIRECT", r);
// it must be an 500
throw new HttpError({
redirect: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Index: FunctionComponent<Props> = ({ repositories }: Props) => {
const [editRepo, setEditRepo] = useState(!Boolean(asset.repositoryId));

const handleUpdate = async (data: Partial<AssetDTO>) => {
console.log("update project");
const resp = await browserApiClient(
"/organizations/" +
activeOrg.slug +
Expand Down
61 changes: 58 additions & 3 deletions src/pages/[organizationSlug]/projects/[projectSlug]/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,58 @@ import Link from "next/link";
import { withOrgs } from "../../../../decorators/withOrgs";
import { withSession } from "../../../../decorators/withSession";
import { useActiveOrg } from "../../../../hooks/useActiveOrg";
import { getApiClientFromContext } from "../../../../services/devGuardApi";
import { browserApiClient, getApiClientFromContext } from "../../../../services/devGuardApi";
import { AssetDTO, ProjectDTO } from "../../../../types/api/api";
import { withOrganization } from "@/decorators/withOrganization";

import { useActiveProject } from "@/hooks/useActiveProject";
import { useForm } from "react-hook-form";
import Section from "@/components/common/Section";
import { ProjectForm } from "@/components/project/ProjectForm";
import { Form } from "@/components/ui/form";
import { withProject } from "@/decorators/withProject";
import { useStore } from "@/zustand/globalStoreProvider";
import { useRouter } from "next/router";
import { Button } from "@/components/ui/button";
interface Props {
project: ProjectDTO & {
assets: Array<AssetDTO>;
};
}

const Index: FunctionComponent<Props> = ({ project }) => {
const Index: FunctionComponent<Props> = ({ project }: Props) => {
const activeOrg = useActiveOrg();
const projectMenu = useProjectMenu();
//const updateProject = useStore((state) => state.updateProject);
const router = useRouter();

const form = useForm<ProjectDTO>({ defaultValues: project });

const handleUpdate = async (data: Partial<ProjectDTO>) => {
console.log("update project");
const resp = await browserApiClient(
"/organizations/" + activeOrg.slug + "/projects/" + project.slug + "/",
{
method: "PATCH",
body: JSON.stringify(data),
},
);

if (!resp.ok) {
console.error("Failed to update project");
}
/*
const newProject = await resp.json();
updateProject(newProject);
if (newProject.slug !== project.slug) {
router.push(
"/"+ activeOrg.slug + "/projects/" + newProject.slug + "/settings",
);
}
*/
};



return (
<Page
Expand Down Expand Up @@ -57,7 +96,21 @@ const Index: FunctionComponent<Props> = ({ project }) => {
</Link>
</span>
}
></Page>
>
<div>
Settings
<Form {...form}>
<form onSubmit={form.handleSubmit(handleUpdate)}>
<Section title="Project" >
<ProjectForm form={form} />
</Section>
<div className="mt-4 flex flex-row justify-end">
<Button>Update</Button>
</div>
</form>
</Form>
</div>
</Page>
);
};

Expand All @@ -82,6 +135,8 @@ export const getServerSideProps = middleware(
session: withSession,
organizations: withOrgs,
organization: withOrganization,
organizations: withOrg,

},
);

Expand Down
4 changes: 3 additions & 1 deletion src/pages/registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ const Registration: NextPage = () => {
};
}, [flow]);

console.log(flow)

const passwordFlow = useMemo(() => {
return {
...flow,
ui: {
...flow?.ui,
nodes:
flow?.ui.nodes?.filter((n) => n.group === UiNodeGroupEnum.Default) ??
flow?.ui.nodes?.filter((n) => n.group === UiNodeGroupEnum.Default || n.group === UiNodeGroupEnum.Password) ??
[],
},
};
Expand Down
1 change: 1 addition & 0 deletions src/zustand/globalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface InitialState {

export interface GlobalStoreActions {
updateAsset: (asset: AssetDTO) => void;
updateProject: (project: ProjectDTO) => void;
}

export interface GlobalStore extends InitialState, GlobalStoreActions {
Expand Down

0 comments on commit 0a913ed

Please sign in to comment.