Skip to content

Commit 64cfc75

Browse files
authored
Merge pull request #694 from trycompai/main
[comp] Production Deploy
2 parents 78638e6 + ec8a81e commit 64cfc75

2 files changed

Lines changed: 35 additions & 18 deletions

File tree

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/policies/[policyId]/components/PolicyOverview.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ export function PolicyOverview({
4747
const [, setOpen] = useQueryState("policy-overview-sheet");
4848
const [, setArchiveOpen] = useQueryState("archive-policy-sheet");
4949
const canCurrentUserApprove = policy?.approverId === activeMember?.id;
50+
const router = useRouter();
5051

5152
const denyPolicyChanges = useAction(denyRequestedPolicyChangesAction, {
5253
onSuccess: () => {
5354
toast.info("Policy changes denied!");
55+
// Force a complete page reload instead of just a refresh
56+
window.location.reload();
5457
},
5558
onError: () => {
5659
toast.error("Failed to deny policy changes.");
@@ -59,7 +62,9 @@ export function PolicyOverview({
5962

6063
const acceptPolicyChanges = useAction(acceptRequestedPolicyChangesAction, {
6164
onSuccess: () => {
62-
toast.info("Policy changes accepted!");
65+
toast.success("Policy changes accepted and published!");
66+
// Force a complete page reload instead of just a refresh
67+
window.location.reload();
6368
},
6469
onError: () => {
6570
toast.error("Failed to accept policy changes.");

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/policies/[policyId]/components/UpdatePolicyOverview.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useAction } from "next-safe-action/hooks";
3030
import { useRef, useState } from "react";
3131
import { toast } from "sonner";
3232
import { SubmitApprovalDialog } from "./SubmitApprovalDialog";
33+
import { useRouter } from "next/navigation";
3334

3435
interface UpdatePolicyOverviewProps {
3536
policy: Policy & {
@@ -49,6 +50,12 @@ export function UpdatePolicyOverview({
4950
const [selectedApproverId, setSelectedApproverId] = useState<string | null>(
5051
null,
5152
);
53+
const router = useRouter();
54+
55+
// Track selected status
56+
const [selectedStatus, setSelectedStatus] = useState<PolicyStatus>(
57+
policy.status,
58+
);
5259

5360
// Date picker state - UI only
5461
const [isDatePickerOpen, setIsDatePickerOpen] = useState(false);
@@ -68,6 +75,7 @@ export function UpdatePolicyOverview({
6875
toast.success("Policy updated successfully");
6976
setIsSubmitting(false);
7077
setFormInteracted(false); // Reset form interaction state after successful update
78+
router.refresh();
7179
},
7280
onError: () => {
7381
toast.error("Failed to update policy");
@@ -81,6 +89,8 @@ export function UpdatePolicyOverview({
8189
setIsSubmitting(false);
8290
setIsApprovalDialogOpen(false);
8391
setFormInteracted(false); // Reset form interaction state after successful submission
92+
setSelectedStatus("needs_review");
93+
router.refresh();
8494
},
8595
onError: () => {
8696
toast.error("Failed to submit policy for approval.");
@@ -163,7 +173,6 @@ export function UpdatePolicyOverview({
163173
// Get form data directly from the DOM
164174
const form = document.getElementById("policy-form") as HTMLFormElement;
165175
const formData = new FormData(form);
166-
const status = formData.get("status") as PolicyStatus;
167176
const assigneeId = (formData.get("assigneeId") as string) || null;
168177
const department = formData.get("department") as Departments;
169178
const reviewFrequency = formData.get("review_frequency") as Frequency;
@@ -180,7 +189,7 @@ export function UpdatePolicyOverview({
180189
setIsSubmitting(true);
181190
submitForApproval.execute({
182191
id: policy.id,
183-
status: "published" as PolicyStatus,
192+
status: PolicyStatus.needs_review,
184193
assigneeId,
185194
department,
186195
review_frequency: reviewFrequency,
@@ -217,27 +226,29 @@ export function UpdatePolicyOverview({
217226
<label htmlFor="status" className="text-sm font-medium">
218227
Status
219228
</label>
220-
<Select
229+
{/* Hidden input for form submission */}
230+
<input
231+
type="hidden"
221232
name="status"
222-
defaultValue={policy.status}
233+
id="status"
234+
value={selectedStatus}
235+
/>
236+
<Select
237+
value={selectedStatus}
223238
disabled={fieldsDisabled}
224-
onValueChange={handleFormChange}
239+
onValueChange={(value) => {
240+
setSelectedStatus(value as PolicyStatus);
241+
handleFormChange();
242+
}}
225243
>
226-
<SelectTrigger>
244+
<SelectTrigger value={selectedStatus}>
227245
<SelectValue placeholder="Select status">
228-
{policy.status && (
229-
<StatusIndicator
230-
status={policy.status}
231-
/>
232-
)}
246+
<StatusIndicator status={selectedStatus} />
233247
</SelectValue>
234248
</SelectTrigger>
235249
<SelectContent>
236-
{Object.values(PolicyStatus)
237-
.filter(
238-
(status) => status !== "needs_review",
239-
)
240-
.map((statusOption) => (
250+
{Object.values(PolicyStatus).map(
251+
(statusOption) => (
241252
<SelectItem
242253
key={statusOption}
243254
value={statusOption}
@@ -246,7 +257,8 @@ export function UpdatePolicyOverview({
246257
status={statusOption}
247258
/>
248259
</SelectItem>
249-
))}
260+
),
261+
)}
250262
</SelectContent>
251263
</Select>
252264
</div>

0 commit comments

Comments
 (0)