feat: onboarding'de diğer KovakSoft uygulamalarından workspace içe aktarma
This commit is contained in:
@@ -86,6 +86,56 @@ export async function createWorkspaceAction(
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
export async function importWorkspaceAction(
|
||||
_prev: WorkspaceState,
|
||||
formData: FormData,
|
||||
): Promise<WorkspaceState> {
|
||||
const teamId = String(formData.get("teamId") ?? "").trim();
|
||||
if (!teamId) return { ok: false, error: "Geçersiz istek." };
|
||||
|
||||
try {
|
||||
const { account, teams, tablesDB } = await createSessionClient();
|
||||
const user = await account.get();
|
||||
|
||||
const allTeams = await teams.list();
|
||||
const team = allTeams.teams.find((t) => t.$id === teamId);
|
||||
if (!team) return { ok: false, error: "Çalışma alanı bulunamadı." };
|
||||
|
||||
const existing = await tablesDB.listRows({
|
||||
databaseId: DATABASE_ID,
|
||||
tableId: TABLES.tenantSettings,
|
||||
queries: [Query.equal("tenantId", teamId), Query.limit(1)],
|
||||
});
|
||||
if (existing.total > 0) return { ok: false, error: "Bu çalışma alanı zaten mevcut." };
|
||||
|
||||
const admin = createAdminClient();
|
||||
await admin.tablesDB.createRow(
|
||||
DATABASE_ID,
|
||||
TABLES.tenantSettings,
|
||||
ID.unique(),
|
||||
{
|
||||
tenantId: teamId,
|
||||
officeName: team.name,
|
||||
createdBy: user.$id,
|
||||
defaultCurrency: "TRY",
|
||||
},
|
||||
[
|
||||
Permission.read(Role.team(teamId)),
|
||||
Permission.update(Role.team(teamId, "owner")),
|
||||
Permission.update(Role.team(teamId, "admin")),
|
||||
Permission.delete(Role.team(teamId, "owner")),
|
||||
],
|
||||
);
|
||||
|
||||
await account.updatePrefs({ ...(user.prefs ?? {}), activeTenant: teamId });
|
||||
await setActiveTenantCookie(teamId);
|
||||
} catch (e) {
|
||||
return { ok: false, error: appwriteError(e) };
|
||||
}
|
||||
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
export async function setActiveTenantAction(tenantId: string) {
|
||||
try {
|
||||
const { account, teams, tablesDB } = await createSessionClient();
|
||||
|
||||
Reference in New Issue
Block a user